[racket] Typed Racket generalization and inference for containers
Hello, Racket community.
I'm a newbie and just started study Racket and Typed Racket and a little
confused with generalization and inference.
I found what inference works different for different containers type. For
example:
Set:
> (set 0 195 196)
- : (Setof Byte)
(set 0 195 196)
List:
> '((195 . 1) (196 . 2))
- : (Listof (Pairof Positive-Byte Positive-Byte)) [generalized from (List
(Pairof Positive-Byte One) (Pairof Positive-Byte Positive-Byte))]
'((195 . 1) (196 . 2))
HashTable:
> #hash((195 . 1) (196 . 2) (197 . 3))
- : (HashTable Integer Integer)
'#hash((195 . 1) (197 . 3) (196 . 2))
Actually i'm writing library for msgpack protocol and decide to implement
it in Typed Racket. Here is my code which did't type check and broke all
other program:
(define-type Atom (U False True Null))
(: atoms (HashTable Byte Atom))
(define atoms #hash((#xc0 . ())
(#xc3 . #t)
(#xc2 . #f)))
Error: Type Checker: Expected (HashTable Byte Atom), but got (HashTable
Integer Atom) in: #hash((195 . #t) (194 . #f) (192 . ()))
Is it bug? Or feature?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130407/84ae46d6/attachment.html>