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
mec...@botik.ru