[racket] Typed racket and hash table

From: Alexander D. Knauth (alexander at knauth.org)
Date: Fri Jun 27 15:59:47 EDT 2014

Are you sure you meant "hash-ref!" and not just "hash-ref”?

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.  

On Jun 27, 2014, at 3:32 PM, Manfred Lotz <manfred.lotz at 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



Posted on the users mailing list.