[racket] Typed Racket frustration

From: Matthew Butterick (mb at mbtype.com)
Date: Sat Jan 24 01:43:19 EST 2015

I've been starting to learn Typed Racket. I discovered this thread when I
ran into the same confusion about the behavior of TR's `hash`. FWIW, Sam's
point that one can't expect every untyped program to work without
modification is entirely fair. But Konrad's point is also fair: if a
function like `append` or `hash` works differently in TR, then it is, for
practical purposes, not the same function, even if it relies on the same
code. If it would be superfluous to repeat every TR function in the
documentation, it still could be valuable to document some of the major
departures from Racket. I mean, I would read that, for sure ;)

PS. I remain curious what one can do with an immutable `hash` function that
takes no arguments, but perhaps it is meant to be a TR koan.



On Wed, Oct 29, 2014 at 10:39 AM, Sam Tobin-Hochstadt <samth at cs.indiana.edu>
wrote:

> 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
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20150123/d7f2fa25/attachment.html>

Posted on the users mailing list.