[racket-dev] Typed Racket interaction

From: Shriram Krishnamurthi (sk at cs.brown.edu)
Date: Mon Aug 2 09:37:41 EDT 2010

Here is a sequence of steps to do something that seems extremely
simple.  I want to create a binary tree of T.

First, I have no idea what this documentation means:

(struct:n (t ...))
is the type of structures named n with field types t.

All of "struct", "n" and "t" are italicized, suggesting they're all
meta-variables.  But only "n" and "t" are explained in the document.
Perhaps "struct:" is meant literally?

After several tries, I figure out no, it doesn't.  Okay, now I know
the basic syntax.

The next few things I do fail miserably, until I get this far:

(define-struct: (T) Node ([v : T] [l : (BinTreeof t)] [r : (BinTreeof t)]))
(define-type (BinTreeof t)
  (U 'empty
     [Node t]))

Now we get a classic impenetrable error message:

  Type Checker: Structure type constructor Node applied to non-regular
  arguments (Error) in: (Node t)

Whatever that means.  I rename the two "t"'s in Node to "T"'s:

(define-struct: (T) Node ([v : T] [l : (BinTreeof t)] [r : (BinTreeof t)]))
(define-type (BinTreeof t)
  (U 'empty
     [Node t]))

Now everything is fine...?!?  TR uses cpp to inline aliases?

Shriram


Posted on the dev mailing list.