On Sun, Mar 4, 2012 at 2:38 PM, Serge D. Mechveliani <[email protected]> wrote:
> On Sun, Mar 04, 2012 at 07:00:38PM +0100, Ralf Hemmecke wrote:
> ...
> )abbrev domain BTREE BTree
> BTree() : Export == Implementation  where
>
>  Export == SetCategory  with
>                         coerce  : %   -> OF
>                         empty   : ()  -> %
>                         tree    : (INT, %, %) -> %
>                         tree1   : INT -> %
>                         sumTree : %   -> INT
>
>  Implementation == add
>     Node ==> Record(val : INT, left : %, right : %)
>     Rep := Union(empty : "empty", node : Node)
>
>     coerce(t) : OutputForm ==
>                 t case empty => "empty" :: OF
>                 nd := t.node
>                 l  := coerce nd.left
>                 r  := coerce nd.right
>                 hconcat["(", nd.val :: OF, ", ", l, ", ", r, ")"]
>
>     empty() == ["empty"]
>     tree(n, l, r) ==  [[n, l, r]]
> ...
>
> 1. I wonder why  ["empty"]  is needed instead of "empty"
>   (I mimiked this stupidly fron  src/algebra/tree.spad*).
>   Similarly is   tree(n, l, r) ==  [[n, l, r]],
>   -- as if additional  []  coerces it to  Rep.
>

Then you should also wonder why two brackets are needed in [[n, l, r]].

The answer is clear from:

(1) -> )show Union(empty : "empty", node : Record(val:INT, left:%, right:%))
 Union(empty: empty,node: Record(val: Integer,left: NIL,right: NIL))
is a domain constructor.
------------------------------- Operations --------------------------------

 ?=? : (%,%) -> Boolean                ?case? : (%,empty) -> Boolean
 ?case? : (%,node) -> Boolean          coerce : % -> OutputForm
 construct : empty -> %                ?.? : (%,empty) -> empty
 ?~=? : (%,%) -> Boolean
 construct : Record(val: Integer,left: NIL,right: NIL) -> %
 ?.? : (%,node) -> Record(val: Integer,left: NIL,right: NIL)

where NIL is shown read %.

The notation [ ... ] is translated as a call to 'construct'.

But your confusion is understandable since the exports of tagged Union
in Axiom are very poorly designed.

Regards,
Bill Page.

-- 
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