[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Axiom-mail] Spad and inductive types
From: |
Gabriel Dos Reis |
Subject: |
Re: [Axiom-mail] Spad and inductive types |
Date: |
07 May 2007 08:11:21 -0500 |
Martin Rubey <address@hidden> writes:
| Dear Gaby,
|
| Gabriel Dos Reis <address@hidden> 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.
Sorry. An inductive type is a kind of union whose members are
inductively defined (like the kind of combinatorial thing you're
doing with Ralf). Here I took a very simplistic datatype, that of
an arithemtic expression over integers:
An arithmetic expression over integer is:
* an integer, or
* addition of two expressions over integer, or
* multiplication of two expressions over integer.
| 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?
MkInt, MkAdd and MkMull (in both Boot and Haskell) are data
cnstructors. Given an integer, MkInt turn it into an Expr.
Simirlarlt, MkAdd and MkMul combines two expressions into an Expr.
So, they have types:
MkInt :: Int -> Expr
MkAdd :: Expr -> Expr -> Expr
MkMul :: Expr -> Expr -> Expr
Furthermore, they can also serves as "tags" to indicate how
expressions of Expr are constructed. That is useful in pattern
matching. In pattern matching, the data constructor serves as tag,
and the operands are variables that are bound to the operands.
-- Gaby
- RE: [Axiom-mail] Spad and inductive types, (continued)
- 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
Re: [Axiom-mail] Spad and inductive types,
Gabriel Dos Reis <=
Re: [Axiom-mail] Spad and inductive types, Bill Page, 2007/05/08
Re: [Axiom-mail] Spad and inductive types, Bill Page, 2007/05/09