[racket] Typed racket and hash table

From: Manfred Lotz (manfred.lotz at arcor.de)
Date: Fri Jun 27 23:21:47 EDT 2014

On Fri, 27 Jun 2014 16:17:01 -0400
Sam Tobin-Hochstadt <samth at cs.indiana.edu>
wrote:

> On Fri, Jun 27, 2014 at 4:08 PM, Manfred Lotz <manfred.lotz at arcor.de>
> wrote:
> > On Fri, 27 Jun 2014 15:59:47 -0400
> > "Alexander D. Knauth"
> > <alexander at 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.
> 
> 
> When you use `hash-ref!`, you're actually changing the hash table, not
> just returning #f in the case that the key isn't found. Typed Racket
> doesn't let you change the hash table to have the wrong kind of data
> in it. So using `hash-ref!` is wrong both with typed or untyped Racket
> -- the type checker is just catching the bug.
> 

You are right. I anyway should have noticed the '!'.


Thanks, Manfred





Posted on the users mailing list.