racketplai

Racket simple AE define-type


From the book "Programming Languages: Application and Interpretation" page 6 I try to code the very first example in DrRacket

#lang typed/racket

(define-type AE
 [num (n number?)]
 [add (lhs AE?) (rhs AE?)]
 [sub (lhs AE?) (rhs AE?)])

But I get the error

aeinterpretter.rkt:5:2: define-type: unexpected term in: (add (lhs AE?) (rhs AE?))

What am I doing wrong here?


Solution

  • You should run this example in the PLAI language:

    #lang plai
    
    (define-type AE
     [num (n number?)]
     [add (lhs AE?) (rhs AE?)]
     [sub (lhs AE?) (rhs AE?)])
    

    The Typed Racket language is a totally different language that gives you most of the power of the base Racket language, but with a static type system. The define-type form in PLAI is a different notion of "type".