[racket] Typed Racket frustration
On Wed, Oct 29, 2014 at 12:32 PM, Konrad Hinsen
<konrad.hinsen at fastmail.net> wrote:
> Of course, the Type Checker can't be wrong, so let's ask it what the type
> of hash is:
>
> ≻ hash
> - : (All (a b) (-> (HashTable a b)))
> #<procedure:hash>
>
> Right, no arguments. So Typed Racket's hash is a restricted version of
> plain Racket's hash. But there is no documentation whatsoever of this
> restriction. Searching the Racket docs for hash yields only the one from
> racket/base.
This isn't a different version of `hash` -- instead, it's the same
version, with a type that doesn't accept every working untyped Racket
program.
This is true in other contexts as well:
-> (append 5)
5
-> (require typed/racket)
-> (append 5)
; Type Checker: Polymorphic function `append' could not be
; applied to arguments:
; Domain: (Listof a) *
; Arguments: Positive-Byte
; in: (append 5)
The type checker can't handle every possible working Racket program,
and thus there are cases where you have to change your program to
accommodate the type checker.
The type of `hash` is one that comes up a bunch, and we should
probably just add a few special cases that handle 2/4/6 arguments.
Unfortunately, we don't yet have a mechanism for fully supporting the
behavior of `hash`, and so there will be cases that work in untyped
Racket but not in Typed Racket.
As for documenting this, the types, which you can print at the REPL,
are the best documentation. Just recently, Asumu added tooltips so
you'll be able to see the type of `hash` online in DrRacket. I don't
think repeating the types for every export of `racket` in the
documentation would be helpful, especially in cases where they're
quite complicated.
Thanks for the useful feedback, and I hope you keep using Typed Racket,
Sam