Hi,

    Jose> I am working on an Computer Algebra system to transform
    Jose> mathematic expressions, possibly simplifing them. There is a
    Jose> data type to represent the expressions:

    Jose> data Expr = Int Integer | Cte String | Var String | App Fn [Expr]

    Jose> An expression may be an integer, a named constante (to
    Jose> represent "known" contantes like pi and e), a variable or an
    Jose> application. An application has a functor (function name) and
    Jose> a list of arguments. The functor is introduced with

    Jose>       data Fn = Sum | Pro | Pow

    Jose> meaning the application may be a sum, a product or a power.

    ...

    Jose> The functions manipulating the expressions also should be
    Jose> extensible to accomodate new algorithms. The extensions is in
    Jose> a form of hooks (based on the Fn component of an application
    Jose> function) in the main algorithms.

I've encountered the same problem and I'm interested to get to know a
highly productive way which at the same time can be considered
a good way of software engineering.
Not enough ... it should pass the Haskell typechecker and be compatible
with the class concept.

At the moment, I know only one "right way": to define several different 
types and define functions on each of these types individually.
That's too much work for me ...

However, the only fast but awful style I know is something like:

data FunctorType = Sum | Pro | Pow | Sin | Trace | UnsafeInput 
                 | ... whatever you like

data AllMyExpressions = SingleConstructor { functor:   FunctorType,
                                            arguments: [AllMyExpressions] }
-- 
 Christoph Herrmann
 E-mail:  [EMAIL PROTECTED]
 WWW:     http://brahms.fmi.uni-passau.de/cl/staff/herrmann.html


Reply via email to