-USING: definitions kernel locals.definitions see see.private typed words
-summary make accessors classes ;
+USING: definitions kernel locals.definitions see see.private typed
+words summary make accessors classes prettyprint ;
IN: typed.prettyprint
PREDICATE: typed-lambda-word < lambda-word "typed-word" word-prop ;
"Typed word “" %
dup word>> name>> %
"” expected input value of type " %
- dup expected-type>> name>> %
+ dup expected-type>> unparse %
" but got " %
dup value>> class-of name>> %
drop
[ ] [ [ \ forget-class forget ] with-compilation-unit ] unit-test
[ ] [ [ \ forget-fail forget ] with-compilation-unit ] unit-test
+
+TYPED: typed-maybe ( x: maybe: integer -- ? ) >boolean ;
+
+[ f ] [ f typed-maybe ] unit-test
+[ t ] [ 30 typed-maybe ] unit-test
+[ 30.0 typed-maybe ] [ input-mismatch-error? ] must-fail-with
combinators.short-circuit definitions effects fry hints
math kernel kernel.private namespaces parser quotations
sequences slots words locals effects.parser
-locals.parser macros stack-checker.dependencies ;
+locals.parser macros stack-checker.dependencies
+classes.union ;
FROM: classes.tuple.private => tuple-layout ;
IN: typed
: unboxable-tuple-class? ( type -- ? )
{
+ [ maybe? not ]
[ all-slots empty? not ]
[ immutable-tuple-class? ]
[ final-class? ]
] [ drop [ ] ] if ;
:: unboxer ( error-quot word types type -- quot )
- type "coercer" word-prop [ ] or
+ type word? [ type "coercer" word-prop ] [ f ] if [ ] or
type type word types error-quot '[ dup _ instance? [ _ _ _ @ ] unless ]
type (unboxer)
compose compose ;