Added sequence typecheck tests

Added empty-sequence type (prints funny but works polymorphically; will submit bug report)
Loosened type of sequence-andmap (can't mimic andmap's predicate type)

original commit: 392d7bfbadee8143f6ec76e965f0c4e31246695e
This commit is contained in:
Neil Toronto 2012-07-10 13:22:53 -07:00
parent 6287ffe3f0
commit c2a4fbc734
2 changed files with 43 additions and 5 deletions

View File

@ -1436,6 +1436,46 @@
#:ret (ret -Boolean (-FS -top -top) (make-Empty))]
[tc-e/t (ann (lambda: ([x : Boolean]) (if x x #t)) (Boolean -> #t)) (t:-> -Boolean (-val #t))]
[tc-e (sequence? 'foo)
-Boolean]
[tc-err (stop-before (inst empty-sequence Symbol) zero?)]
[tc-e (stop-before (inst empty-sequence Integer) zero?)
(-seq -Int)]
[tc-e (stop-after (inst empty-sequence Integer) zero?)
(-seq -Int)]
[tc-e (sequence->list (inst empty-sequence Symbol))
(-lst -Symbol)]
[tc-e (sequence-length (inst empty-sequence Symbol))
-Nat]
[tc-e (sequence-ref (inst empty-sequence Symbol) 0)
-Symbol]
[tc-e (sequence-tail (inst empty-sequence Symbol) 0)
(-seq -Symbol)]
[tc-e (sequence-append empty-sequence (inst empty-sequence Symbol))
(-seq -Symbol)]
[tc-e (sequence-append (inst empty-sequence Symbol) (inst empty-sequence Integer))
(-seq (t:Un -Symbol -Int))]
[tc-e (sequence-map add1 (inst empty-sequence Integer))
(-seq -Int)]
[tc-err (sequence-andmap zero? (inst empty-sequence Symbol))]
[tc-e (sequence-andmap zero? (inst empty-sequence Integer))
-Boolean]
[tc-e (sequence-andmap add1 (inst empty-sequence Integer))
(t:Un -Int (-val #t))]
[tc-e (sequence-ormap zero? (inst empty-sequence Integer))
-Boolean]
[tc-e (sequence-ormap add1 (inst empty-sequence Integer))
(t:Un -Int (-val #f))]
[tc-e (sequence-fold (lambda: ([y : (Listof Symbol)] [x : Symbol]) (cons x y))
null empty-sequence)
(-lst -Symbol)]
[tc-e (sequence-count zero? (inst empty-sequence Integer))
-Nat]
[tc-e (sequence-filter zero? (inst empty-sequence Integer))
(-seq -Int)]
[tc-e (sequence-add-between (inst empty-sequence Integer) 'foo)
(-seq (t:Un -Int (-val 'foo)))]
)
(test-suite
"check-type tests"

View File

@ -941,16 +941,14 @@
;; Doesn't work (mu types are single-valued only):
;[sequence-generate* (-poly (a) ((-seq a) . -> . (-mu t (-values (list (Un (-lst a) (-val #f)) t)))))]
;; Doesn't render nicely (but seems to work fine):
;[empty-sequence (-poly (a) (-seq a))]
[empty-sequence (-poly (a) (-seq a))]
[sequence->list (-poly (a) ((-seq a) . -> . (-lst a)))]
[sequence-length (-poly (a) ((-seq a) . -> . -Integer))]
[sequence-length (-poly (a) ((-seq a) . -> . -Nat))]
[sequence-ref (-poly (a) ((-seq a) -Integer . -> . a))]
[sequence-tail (-poly (a) ((-seq a) -Integer . -> . (-seq a)))]
[sequence-append (-poly (a) (->* (list) (-seq a) (-seq a)))]
[sequence-map (-poly (a b) ((a . -> . b) (-seq a) . -> . (-seq b)))]
[sequence-andmap (-poly (a b t) (make-pred-ty (list (make-pred-ty (list a) b t) (-seq a))
(Un b (-val #t))
(-seq t)))]
[sequence-andmap (-poly (a b) ((a . -> . b) (-seq a) . -> . (Un b (-val #t))))]
[sequence-ormap (-poly (a b) ((a . -> . b) (-seq a) . -> . (Un b (-val #f))))]
[sequence-for-each (-poly (a) ((a . -> . Univ) (-seq a) . -> . -Void))]
[sequence-fold (-poly (a b) ((b a . -> . b) b (-seq a) . -> . b))]