On Wed, May 02, 2012 at 11:38:07AM -0700, Grigory Sarnitsky wrote:
> Thank you guys. For some weired reason I thought one cannot define two
> distinct types, one being defined type in terms of the other, the other
> being defined through the first one. I should have tried before asking. At
> least in Haskell I can do it:
>
> {-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
>
> import Math.Core.Field
> import Math.CommutativeAlgebra.Polynomial
> import Math.Algebras.Structures
>
> type Expression = GlexPoly Q Kernel
>
> data Kernel = Symbol String
> | Exp Expression
> deriving (Eq, Ord)
>
> instance Show Kernel where
> show (Symbol str) = str
> show (Exp x) = "exp(" ++ show x ++ ")"
>
> instance Floating Expression where
> exp = glexvar.Exp
>
> compiled! I was really surprised, but it works:
>
> *Main> let [x, y] = map glexvar [Symbol "x", Symbol "y"]
> *Main> 13*x*y + exp(y^3 + x^2 - exp(x) + 4*exp(x))
> 13xy+exp(y^3+x^2+3exp(x))
>
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.
------
Sergei
--
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.