On Sun, Mar 04, 2012 at 10:22:18AM +0100, Ralf Hemmecke wrote:
>> The question can be reformulated:  what Spad has for the  tagged union?.
>
> Tagged union in SPAD is something like
>
>   Union(i: Integer, f: Fraction Integer, ...)
>

Please, where it is described how to use it?


> but I bet, that is not what you want, since it is not equivalent to Haskell.
>
>> The initial goal is explained in the first my letter on this subject.
>
> Yes, I understood that part. But you haven't expressed the WHY.
> Why would you want to put everything into one big type?


I am trying to compose a  Spad  function  parseCall  which parses from a  
String  a function call, for a certain restricted set of functions, 
with parsing domain descriptions and the corresponding argument 
descriptions, and a package call description -- given all in one  String.

I am going to provide a working program for  parseCall  and then, to ask
whether it is reasonably done.

But I met an obstacle:  I do not know how to define a
                                             _recursive tagged type_.
Example
-------
  a Tree over a type T  is either a  Leaf  or
  a  Node  containing  v: T,  left branch Tree,  and  right branch Tree.

In Haskell, this can be defined by intruducing a user type constructor
Tree  and its type:
              data Tree a =  Leaf a | Node a (Tree a) (Tree a)

For example,
    (Node 1  (Node 11 (Leaf 111) (Node 112 (Leaf 1121) (Leaf 1122)))
             (Leaf 12)
    )
    -- :: Tree Integer

represents the tree      1
                       /   \
                     11     12
                   /    \
                        111     112
                       /   \
                   1121    1122

Example:  the function  f  sums the numbers in all the tree:

    f :: Tree -> Integer
    f tree = case tree of  Leaf n            -> n
                           Node n left right -> n + (f left) + (f right)

What is the most appropiate approach in Spad to definig  Tree(T) ?
I try  Tree INT :

---------------------------------------------
INT  ==> Integer
Tree ==> Union(Integer, Node)

)abbrev package FOO Foo
Foo() : with        tree1 : INT -> Tree
 == add
  Node : Type :=
              Record(nodeVal : INT, nodeLeft : Tree, nodeRight : Tree)

  tree1(n : INT) : Tree ==  n :: Tree
---------------------------------------------

-- and  tree1(2)  does not work.

Thank you for advices,

------
Sergei
[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to