Add type for range, and extend in-range's.

original commit: ee142047f801da2cac93b681c368921e8f2a2541
This commit is contained in:
Vincent St-Amour 2012-06-20 17:08:16 -04:00
parent dcffc90c3f
commit d2e69a68dc
3 changed files with 48 additions and 7 deletions

View File

@ -207,6 +207,10 @@
[tc-e/t #(2 3 #t) (make-HeterogenousVector (list -Integer -Integer -Boolean))]
[tc-e (vector 2 "3" #t) (make-HeterogenousVector (list -Integer -String -Boolean))]
[tc-e (vector-immutable 2 "3" #t) (make-HeterogenousVector (list -Integer -String -Boolean))]
[tc-e (range 4) (-lst -Byte)]
[tc-e (range 2 4 1) (-lst -PosByte)]
[tc-e (range 0 4 1) (-lst -Byte)]
[tc-e (range 0.0 4/2 0.5) (-lst -Flonum)]
[tc-e/t '(#t #f) (-lst* (-val #t) (-val #f))]
[tc-e/t (plambda: (a) ([l : (Listof a)]) (car l))
(make-Poly '(a) (t:-> (make-Listof (-v a)) (-v a)))]

View File

@ -215,6 +215,29 @@
[range (cl->* (-> (Un -Zero -NegInt) (-val '()))
(-> -One (-pair -One (-val '())))
(-> -Byte (-lst -Byte))
(-> -Index (-lst -Index))
(-> -Fixnum (-lst -Fixnum))
(-> -Real (-lst -Int))
(->opt -PosInt -Byte [-Int] (-lst -PosByte))
(->opt -Nat -Byte [-Int] (-lst -Byte))
(->opt -PosInt -Index [-Int] (-lst -PosIndex))
(->opt -Nat -Index [-Int] (-lst -Index))
(->opt -Nat -NonNegFixnum [-Int] (-lst -NonNegFixnum))
(->opt -PosInt -Fixnum [-Nat] (-lst -PosFixnum))
(->opt -Nat -Fixnum [-Nat] (-lst -NonNegFixnum))
(->opt -Nat -Nat [-Int] (-lst -Nat))
(->opt -PosInt -Int [-Nat] (-lst -PosInt))
(->opt -Nat -Int [-Nat] (-lst -Nat))
;; could add cases that guarantee lists of negatives, etc.
(->opt -Int -Real [-Int] (-lst -Int))
(->opt -Rat -Real [-Rat] (-lst -Rat))
(->opt -Flonum -Real [-Flonum] (-lst -Flonum))
(->opt -SingleFlonum -Real [-SingleFlonum] (-lst -SingleFlonum))
(->opt -InexactReal -Real [-InexactReal] (-lst -InexactReal))
(->opt -Real -Real [-Real] (-lst -Real)))]
[take (-poly (a) ((-lst a) index-type . -> . (-lst a)))]
[drop (-poly (a) ((-lst a) index-type . -> . (-lst a)))]
[take-right (-poly (a) ((-lst a) index-type . -> . (-lst a)))]

View File

@ -70,13 +70,27 @@
(-> Univ (-seq a b) (seq-vals (list a b))))))]
;; in-range
[(make-template-identifier 'in-range 'racket/private/for)
(cl->* (-Byte [-Byte -Byte] . ->opt . (-seq -Byte))
(-PosFixnum -Fixnum [-Nat] . ->opt . (-seq -PosFixnum))
(-NonNegFixnum [-Fixnum -Nat] . ->opt . (-seq -NonNegFixnum))
(-Fixnum [-Fixnum -Int] . ->opt . (-seq -Fixnum))
(-PosInt -Int [-Nat] . ->opt . (-seq -PosInt))
(-Nat [-Int -Nat] . ->opt . (-seq -Nat))
(-Int [-Int -Int] . ->opt . (-seq -Int)))]
(cl->* (-> -Byte (-seq -Byte))
(-> -Index (-seq -Index))
(-> -Fixnum (-seq -Fixnum))
(-> -Real (-seq -Int))
(->opt -PosInt -Byte [-Int] (-seq -PosByte))
(->opt -Nat -Byte [-Int] (-seq -Byte))
(->opt -PosInt -Index [-Int] (-seq -PosIndex))
(->opt -Nat -Index [-Int] (-seq -Index))
(->opt -Nat -NonNegFixnum [-Int] (-seq -NonNegFixnum))
(->opt -PosInt -Fixnum [-Nat] (-seq -PosFixnum))
(->opt -Nat -Fixnum [-Nat] (-seq -NonNegFixnum))
(->opt -Nat -Nat [-Int] (-seq -Nat))
(->opt -PosInt -Int [-Nat] (-seq -PosInt))
(->opt -Nat -Int [-Nat] (-seq -Nat))
;; could add cases that guarantee lists of negatives, etc.
(->opt -Int -Real [-Int] (-seq -Int))
(->opt -Rat -Real [-Rat] (-seq -Rat))
(->opt -Flonum -Real [-Flonum] (-seq -Flonum))
(->opt -SingleFlonum -Real [-SingleFlonum] (-seq -SingleFlonum))
(->opt -InexactReal -Real [-InexactReal] (-seq -InexactReal))
(->opt -Real -Real [-Real] (-seq -Real)))]
;; in-naturals
[(make-template-identifier 'in-naturals 'racket/private/for)
(cl->* (-> -PosInt (-seq -PosInt))