Dear Gaby,

Gabriel Dos Reis <[EMAIL PROTECTED]> writes:

>   For concretness, here is a very classic example of inductive type
> along with a function working on expression of such type, written in
> both Haskell and New Boot.  How would you best write that in Spad?

I'm very sorry, but I do not understand the code below.  Could you describe
what it is supposed to do?  I guess: Expr is the name of the type (= domain?)
you want to create, and it exports a single operation called "eval", which
returns an integer.  But what is MkInt, MkAdd and MkMul?  Perhaps you want to
say that an element in Expr can be of three forms, namely MkInt, MkAdd or
MkMul?

Martin

 
> ------8<----- Begin Haskell code ------8<-----
> data Expr = MkInt Int
>           | MkAdd Expr Expr
>         | MkMul Expr Expr
> 
> eval::Expr -> Int
> eval (MkInt i) = i
> eval (MkAdd x y) = (eval x) + (eval y)
> eval (MkMul x y) = (eval x) * (eval y)
> ------8<----- End Haskell code ------8<-------
> 
> 
> Here is the same thing written in New Boot
> 
> ------8<----- Begin Boot code ------8<-----
> structure Expr == 
>    MkInt(Integer)
>    MkAdd(Expr, Expr)
>    MkMul(Expr, Expr)
> 
> eval e ==
>   case e of
>      MkInt(i) => i
>      MkAdd(x, y) => eval(x) + eval(y)
>      MkMul(x, y) => eval(x) * eval(y)
>      otherwise => error "should not happen"
> ------8<----- End Boot code ------8<-------
> 
> 
> For the curious, the above New Boot code is translated as
> shown below.
> 
> How would you write that in Spad.  Please, keep the discussion
> on axiom-mail.
> 
> Thanks!
> 
> -- Gaby
>  
> ; structure Expr == 
> ;    MkInt(Integer)
> ;    MkAdd(Expr, Expr)
> ;    MkMul(Expr, Expr)
>  
> (DEFUN |MkInt| #0=(|bfVar#1|) (CONS '|MkInt| (LIST . #0#)))
> (DEFUN |MkAdd| #0=(|bfVar#2| |bfVar#3|) (CONS '|MkAdd| (LIST . #0#)))
> (DEFUN |MkMul| #0=(|bfVar#4| |bfVar#5|) (CONS '|MkMul| (LIST . #0#)))
>  
> ; eval e ==
> ;   case e of
> ;      MkInt(i) => i
> ;      MkAdd(x, y) => eval(x) + eval(y)
> ;      MkMul(x, y) => eval(x) * eval(y)
> ;      otherwise => error "should not happen"
>  
> (DEFUN |eval| (|e|)
>   (PROG (|bfVar#7| |bfVar#6|)
>     (RETURN
>       (PROGN
>         (SETQ |bfVar#6| |e|)
>         (SETQ |bfVar#7| (CDR |bfVar#6|))
>         (CASE (CAR |bfVar#6|)
>           (|MkInt| (LET ((|i| (CAR |bfVar#7|))) |i|))
>           (|MkAdd| (LET ((|x| (CAR |bfVar#7|)) (|y| (CADR |bfVar#7|)))
>                      (+ (|eval| |x|) (|eval| |y|))))
>           (|MkMul| (LET ((|x| (CAR |bfVar#7|)) (|y| (CADR |bfVar#7|)))
>                      (* (|eval| |x|) (|eval| |y|))))
>           (T (|error| '|should not happen|)))))))
> 
> 
> 
> _______________________________________________
> Axiom-mail mailing list
> Axiom-mail@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/axiom-mail



_______________________________________________
Axiom-mail mailing list
Axiom-mail@nongnu.org
http://lists.nongnu.org/mailman/listinfo/axiom-mail

Reply via email to