[racket] Typed Racket frustration

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Wed Oct 29 12:32:30 EDT 2014

It's one of those days when I wonder if I should keep on playing with
Typed Racket.  It's just too frustrating.

Like my previous frustration events, today's is related to the fact
that Typed Racket implements only some subset of Racket, but that this
is not documented anywhere. On the contrary, the documentation suggests
that my code should work but it doesn't.

Here's an illustration of today's problem. Of course it happened in the
middle of some complex expression in real life - Murphy at work. But even
in this minimal example it's surprising.

------------------------------
#lang typed/racket

(: foo (HashTable Integer Integer))
(define foo (hash 1 2))
------------------------------

The error message is:

------------------------------
 Type Checker: Polymorphic function `hash' could not be applied to arguments:
Wrong number of arguments - Expected 0, but got 2

Argument 1:
  Expected: -none-
  Given:    One
Argument 2:
  Expected: -none-
  Given:    Positive-Byte
------------------------------

DrRacket immediately pops up the documentation of (hash...) to help me:

------------------------------
 (hash key val ... ...) → (and/c hash? hash-equal? immutable?)

  key : any/c
  val : any/c
------------------------------

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.

Last week's frustration was with for/set. Typed Racket doesn't have its own,
but picks up the one standard Racket which it can't typecheck. You get an
error message from the type checker that you need to add more annotation, and
when you do you get a syntax error. No hint whatsoever that Typed Racket
simply can't handle for/set.

How does anyone get any real work done with Typed Racket?

Konrad.


Posted on the users mailing list.