[plt-scheme] writing an evaluation function/interpreter; type-case

From: ih (irvin.hwang at gmail.com)
Date: Wed Feb 17 17:21:35 EST 2010

Hi,
I'm trying to follow Ch. 4 of Types and Programming Languages by
Benjamin Pierce and implement the language

t:= true | false | if t then t else t
OR using define-type
(define-type term
  [TmTrue (t (lambda (a) (equal? a #t)))]
  [TmFalse (f (lambda (a) (equal? a #f)))]
  [TmIf (t1 term?) (t2 term?) (t3 term?)])

I was trying to use the forms define-type and type-case from PLAI by
Shriram Krishnamurthi, but type-case doesn't seem to have the same
pattern matching functionality as is used Pierce's ocaml
implementation i.e.  I can't write

(define (eval1 e)
  (type-case term e
             [TmTrue (t) t]
             [TmFalse(f) f]
             [TmIf (TmTrue t2 t3) (eval1 t2)]
             [TmIf (TmFalse t2 t3) (eval1 t3)]))

I was trying to use "match", but it doesn't seem to be defined to work
with the algebraic data type defined with define-type (or perhaps I am
using match incorrectly).

(define (eval1 e)
  (type-case term e
             [TmTrue (t) t]
             [TmFalse(f) f]
             [TmIf (t1 t2 t3) (match t1)
]



  Can anyone give guidance on the proper way to implement this in
scheme?  Should I be using match with define-type?



Posted on the users mailing list.