On Wed, May 02, 2012 at 03:47:25PM -0400, Bill Page wrote:
> On Wed, May 2, 2012 at 3:24 PM, Serge D. Mechveliani <[email protected]> wrote:
> >
> > Such types also can be defined in {\tt Spad}, but the code will
> > be considerably more complex (I complained on this).
> > As an example, see in the Axiom source the definition for the
> > domain of BinaryTree (or, maybe, Tree).
> > I wonder whether it is simpler in Aldor.
> >
> 
> In the context of this group I find your comment rather annoying and I
> wonder how you define "complex" in such a way that it allows an
> objective comparison.
> 
> Regards,
> Bill Page.


I discussed in this e-mail list of how to define in  Spad 
ConstructedDomain  -- a domain supplied with a certain explicit 
construction. 
I managed to build such only with a strong assistance of the FriCAS 
people. And the definition has occurred very complex.

If you need a concrete example, let us try first something simple.
For example, a  _binary search tree_.
Of course, it is for defining as a  _user type_, not of the library.
In Haskell, the user can define it, for example, as 

------------------------------------------------------------------------
data STree key value =  
              Empty | Node key value (STree key value) (STree key value)
              deriving (Show)

-- key, value  are type parameters (parameters of a domain in Spad).
-- It is either  Empty  or  a node containing key, value, left subtree, 
--                                                        right subtree.
-- `deriving (Show)'  means the default definition for printing of this
--                    data to String.

search :: Ord key => key -> STree key value -> Maybe value

-- `::'  is `:' of Spad,   `='  is  `==', `:=' of  Spad.    
-- `Ord key =>'  corresponds to the condition of
--               key : OrderedSet  in the domain declaration  in Spad.
--               The used  `compare'  operation is of the class Show. 
-- `search' is a polymorphic function. And in Spad, it needs, probably,
--          to be exported by the domain STree. 

search k tab = case tab 
               of
               Empty                             -> Nothing
               Node k' v leftBranch rightBranch ->
                                    case compare k k' 
                                    of
                                    EQ -> Just v
                                    LT -> search k leftBranch
                                    _  -> search k rightBranch

main = putStr (concat [show tree, "\n\nv = ", show v, "\n"]) 

       -- Example of usage. Buld some tree for  key = Int, value = Char,
       --                   search the value for 2 in it,  
       --                   print the tree and the found value.  
       where
       tree = Node 1 'a' Empty 
                         (Node 2 'b' (Node 3 'c' Empty Empty) Empty)
       v = search 2 tree
------------------------------------------------------------------------

Compiling, running under GHC:

           > ghc --make -O Main  
           > ./Main

           Node 1 'a' Empty (Node 2 'b' (Node 3 'c' Empty Empty) Empty)

           v = Just 'b'


What is the Spad program for this?
This is not a flame war. Because
1) I respect Axiom, and even try to use it in the interface project,
2) you asked for an example,
3) if the Spad code occurs considerably more complex, this would not
   mean too much, for example, a) Haskell has not dynamic types, one can
               not program parsing a domain in Haskell as I did in Spad,
   b) Spad has considerably more of overloading,
4) if the Spad code is sufficiently simple, then I could return to my
   ConstructedDomain in Spad and see how can it be improved.
 
Regards,

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