From c2a4fbc734e2e9e5e8a59cb62f73d90312b7eb17 Mon Sep 17 00:00:00 2001 From: Neil Toronto Date: Tue, 10 Jul 2012 13:22:53 -0700 Subject: [PATCH] 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 --- .../unit-tests/typecheck-tests.rkt | 40 +++++++++++++++++++ collects/typed-racket/base-env/base-env.rkt | 8 ++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/collects/tests/typed-racket/unit-tests/typecheck-tests.rkt b/collects/tests/typed-racket/unit-tests/typecheck-tests.rkt index def41d3e..69551022 100644 --- a/collects/tests/typed-racket/unit-tests/typecheck-tests.rkt +++ b/collects/tests/typed-racket/unit-tests/typecheck-tests.rkt @@ -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" diff --git a/collects/typed-racket/base-env/base-env.rkt b/collects/typed-racket/base-env/base-env.rkt index 690b8543..2a2b174e 100644 --- a/collects/typed-racket/base-env/base-env.rkt +++ b/collects/typed-racket/base-env/base-env.rkt @@ -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))]