[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-mail] Spad and inductive types
From: |
Martin Rubey |
Subject: |
Re: [Axiom-mail] Spad and inductive types |
Date: |
07 May 2007 10:14:19 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 |
Here you go. But I doubt somehow that Gaby had this in mind, since this is
quite usual stuff in Axiom (grep "Rep.*Union")
Martin
)abbrev domain EX Expr
Expr(): with
eval: % -> Integer
coerce: Integer -> %
coerce: % -> OutputForm
_+: (%,%) -> %
_*: (%,%) -> %
== add
MkInt ==> Integer
MkAdd ==> Record(lAdd:%,rAdd:%)
MkMul ==> Record(lMul:%,rMul:%)
-- Rep shouldn't be a macro, I think
Rep := Union(MkInt, MkAdd, MkMul)
eval(x:%): Integer ==
-- in SPAD, conversion from Rep to Union(MkInt, ...) is implicit
x case MkInt => x
-- without package calling + the compiler picks + from %...
x case MkAdd => (eval(x.lAdd) + eval(x.rAdd))$Integer
x case MkMul => (eval(x.lMul) * eval(x.rMul))$Integer
coerce(n: Integer) == n::Rep
x + y == [x,y]$MkAdd :: Rep
x * y == [x,y]$MkMul :: Rep
coerce(x: %): OutputForm ==
x case MkInt => outputForm x
x case MkAdd => hconcat [message "(", _
(x.lAdd)::OutputForm, _
message "+", _
(x.rAdd)::OutputForm, _
message ")"]
x case MkMul => hconcat [message "(", _
(x.lMul)::OutputForm, _
message "*", _
(x.rMul)::OutputForm, _
message ")"]
- [Axiom-mail] Spad and inductive types, Gabriel Dos Reis, 2007/05/06
- Re: [Axiom-mail] Spad and inductive types, Martin Rubey, 2007/05/07
- RE: [Axiom-mail] Spad and inductive types, Bill Page, 2007/05/07
- Re: [Axiom-mail] Spad and inductive types, Gabriel Dos Reis, 2007/05/07
- RE: [Axiom-mail] Spad and inductive types, Bill Page, 2007/05/08
- Re: [Axiom-mail] Spad and inductive types, Ralf Hemmecke, 2007/05/08
- RE: [Axiom-mail] Spad and inductive types, Gabriel Dos Reis, 2007/05/08
- Re: [Axiom-mail] Spad and inductive types, Ralf Hemmecke, 2007/05/08
- Re: [Axiom-mail] Spad and inductive types, Ralf Hemmecke, 2007/05/08
- Re: [Axiom-mail] Spad and inductive types, Gabriel Dos Reis, 2007/05/08
- Re: [Axiom-mail] Spad and inductive types, Gabriel Dos Reis, 2007/05/07