[plt-scheme] Re: writing an evaluation function/interpreter; type-case
Thanks for the response. I'm not sure what it means to "push the test
down one level."
On Feb 17, 5:35 pm, Jay McCarthy <jay.mccar... at gmail.com> wrote:
> On Wed, Feb 17, 2010 at 3:21 PM, ih <irvin.hw... at gmail.com> wrote:
> > 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?
>
> You can push the test down one level.
>
> Or you can use match and define-struct.
>
> > Should I be using match with define-type?
>
> They do not work together.
>
>
>
> > _________________________________________________
> > For list-related administrative tasks:
> > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> --
> Jay McCarthy <j... at cs.byu.edu>
> Assistant Professor / Brigham Young Universityhttp://teammccarthy.org/jay
>
> "The glory of God is Intelligence" - D&C 93
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme