On Fri, 27 Jun 2014 15:59:47 -0400 "Alexander D. Knauth" <alexan...@knauth.org> wrote:
> Are you sure you meant "hash-ref!" and not just "hash-ref”? > Well I thought hash-ref! is the way to go because I just wanted #f in case of not found. > Because even with (hash-ref! my-hash size (lambda () #f)), it would > expect the #f to be of type (Listof String), which it isn’t. > Oops, that makes the difference. Using hash-ref works fine now. It seems that in untyped racket hash-ref! is fine but it is not suited for typed racket. Thanks a lot, Manfred > On Jun 27, 2014, at 3:32 PM, Manfred Lotz > <manfred.l...@arcor.de> wrote: > > > I tried this: > > > > #lang typed/racket/base > > > > (: my-hash (HashTable Nonnegative-Integer (Listof String))) > > (define my-hash (make-hash)) > > > > > > > > (: my-hash-add (-> Nonnegative-Integer String Void)) > > (define (my-hash-add size s) > > (let* ([val (hash-ref! my-hash size #f)]) > > (if val > > (hash-set! my-hash size (cons s val)) > > (hash-set! my-hash size (list s))))) > > > > and got: > > > > test.rkt:10:14: Type Checker: Polymorphic function `hash-ref!' could > > not be applied to arguments: Argument 1: > > Expected: (HashTable a b) > > Given: (HashTable Nonnegative-Integer (Listof String)) > > Argument 2: > > Expected: a > > Given: Nonnegative-Integer > > Argument 3: > > Expected: (-> b) > > Given: False > > > > in: (hash-ref! my-hash size #f) > > context...: > > > > /home/manfred/racket/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:249:0: > > type-check > > /home/manfred/racket/share/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:40:0: > > tc-setup > > /home/manfred/racket/share/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:25:4 > > standard-module-name-resolver > > > > > > What can I do to make this work? > > > > > > -- > > Manfred > > > > > > > > > > ____________________ > > Racket Users list: > > http://lists.racket-lang.org/users > > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users > ____________________ Racket Users list: http://lists.racket-lang.org/users