diff --git a/manual/Types b/manual/Types index 6d5de10..cab029d 100644 --- a/manual/Types +++ b/manual/Types @@ -158,6 +158,12 @@ or {{:}} should follow the syntax given below: (*) Note: no type-variables are bound inside {{(not TYPE)}}. +You can use a shorthand {{'SYMBOL}} for introducing free variables in +{{forall}} types, examples: + + ('a -> 'a) is translated to (forall (a) (a -> a)) + (forall (a) ('a -> a)) is translated to (forall (a) (a -> a)) + Note that type-variables in {{forall}} types may be given "constraint" types, i.e. (: sort (forall (e (s (or (vector-of e) (list-of e)))) diff --git a/scrutinizer.scm b/scrutinizer.scm index ece07ed..6d4a0c8 100644 --- a/scrutinizer.scm +++ b/scrutinizer.scm @@ -1967,6 +1967,16 @@ (second t)) constraints)) (validate (third t) rec))))) + ((and (eq? 'quote (car t)) + (pair? (cdr t)) + (symbol? (second t)) + (null? (cddr t)) + (second t)) + => + (lambda (v) + (unless (memq v typevars) + (set! typevars (cons v typevars))) + v)) ((eq? 'or (car t)) (and (list? t) (let ((ts (map validate (cdr t)))) diff --git a/tests/typematch-tests.scm b/tests/typematch-tests.scm index 44c6c32..8a01094 100644 --- a/tests/typematch-tests.scm +++ b/tests/typematch-tests.scm @@ -3,6 +3,7 @@ (import chicken.blob chicken.condition chicken.memory chicken.locative) +(define something) (define (make-list n x) (list-tabulate n (lambda _ x))) @@ -394,3 +395,22 @@ (compiler-typecase #x7fffffffffffffff (fixnum #f) (bignum #t))) + +(assert + (compiler-typecase 1 + ('a #t))) + +(assert + (compiler-typecase (the (list fixnum string string) something) + ((list 'a 'a 'b) #f) + ((list 'a 'b 'b) #t))) + +(assert + (compiler-typecase (the (list fixnum string string) something) + ((forall (a) (list a 'a 'b)) #f) + ((forall (b) (list 'a 'b b)) #t))) + +(assert + (compiler-typecase (the (list string (list string fixnum)) something) + ((list 'a (forall (a) (list 'b a))) #f) + ((list 'b (forall (b) (list b 'a))) #t)))