[racket] Typed Racket frustration

From: Daniel Feltey (dfeltey at ccs.neu.edu)
Date: Thu Oct 30 10:23:16 EDT 2014

> I wouldn't expect the type checker to support all working plain Racket
> code. But I do expect Typed Racket to provide equivalent (though
> possibly syntactically different) APIs for common tasks such as
> creating an immutable hash table from key-value pairs.
>
> I suppose the problem with hash is the indefinite number of arguments.
> One way out is a list of key-value pairs, with hash becoming the inverse
> of hash->list. It's certainly much easier to port untyped code to such a
> somewhat different syntax than to have no straightforward option at all.
>
> This is BTW what I used as a workaround:
> 
>  (: list->hash (All (a b) (-> (Listof (Pairof a b)) (HashTable a b))))
>  (define (list->hash lst)
>    (for/fold ([hsh : (HashTable a b) (hash)])
>              ([kv : (Pairof a b) lst])
>      (hash-set hsh (car kv) (cdr kv))))

Have you tried using `make-hash` or `make-immutable-hash`? I think they do exactly what you're looking for.

Dan




Posted on the users mailing list.