[racket] Typed Racket: (Parameterof (HashTable ...))

From: Greg Hendershott (greghendershott at gmail.com)
Date: Fri Feb 14 20:17:44 EST 2014

Starting to try Typed Racket for real. It's been really fun!
Overall the error messages have been clear and helpful. Only
a couple things so far have stumped me. Here's one.

Although this is fine:

    (: h (HashTable Symbol String))
    (define h (make-hash))

This is an error:

    (: ph (Parameterof (HashTable Symbol String)))
    (define ph (make-parameter (make-hash)))

    ; Type Checker: Polymorphic function `make-hash' could not be
applied to arguments:
    ; Domains: (Listof (Pairof a b))
    ;
    ; Arguments:
    ;
    ;   in: (make-hash)

1. I don't understand why. Why does `(make-hash)` satisfy
`(HashTable Symbol String)` alone, but not wrapped in
`Parameterof`?

2. I'm not sure what the appropriate resolution is.

(a) Although this typechecks...

    (: ph (Parameterof (HashTable Symbol String)))
    (define ph (make-parameter (make-hash '([n/a . ""]))))

...it's a kludge.

(b) From the REPL I see that the type of `(make-hash)` is
`(HashTable Any Any)`. Although I _could_ try:

    (: ph (Parameterof (U (HashTable Any Any)
                          (HashTable Symbol String))))
    (define ph (make-parameter (make-hash )))

(i) that's not correct (why bother typing it Any/Any?)
(ii) that gives the same original type check error above

Posted on the users mailing list.