[racket] An easy route to define-datatype in BSL?

From: Prabhakar Ragde (plragde at uwaterloo.ca)
Date: Sun Nov 4 16:59:26 EST 2012

I'm debating trying to use something like define-datatype, as used in 
EOPL and PLAI (and available in the Racket languages that support those 
books) early in my first-year undergraduate class. (Opinions on the 
wisdom of this, or on my sanity in general, by direct e-mail, please.)

In a teaching-language program, just using `require' to include 
define-datatype and type-case or 'cases' from plai/datatype.rkt or 
eopl/datatype.rkt appears to work so long as the teaching language is 
ISL or higher. In BSL or BSL+, I seem to be running into a thicket of 
rules designed to protect students. I'm using as my exploratory example 
the trivial arithmetic expression evaluator from the beginning of PLAI 
(2007 edition). Using plai/datatype.rkt generates an error because a use 
of define-datatype involves function names in expression positions (as 
contracts for field names). If I wrap these in applications of 
first-order->higher-order from lang/prim, which seems to be designed for 
this task, I get an error the first time I try to use a variant 
constructor (in the PLAI example, in 'parse'). The constructors seem to 
be defined, but also seem to be regarded as variables instead of 
functions. This is also what happens with eopl/datatype.rkt (the other 
error does not seem to arise).

Do I have a hope of pulling this off, and if so, how? Many thanks. --PR

Posted on the users mailing list.