[Haskell] evaluate function as a string
Tomasz Zielonka
t.zielonka at students.mimuw.edu.pl
Fri Apr 23 11:42:58 EDT 2004
On Fri, Apr 23, 2004 at 03:32:54AM +0200, Sebastian Sylvan wrote:
>
> First you need to parse the expression into a Haskell data type. For
> this I would recommend Parsec (see Haskell.org). The Haskell data type
> would be something like
>
> data Expr = AtomD Double | AtomI Integer | Add Expr Expr | Mul Expr Expr
> | Sub Expr Expr | ....
There is no need to introduce a datatype - for one parameter functions
you can parse text directly to a (Double -> Double) function. Of course
if you want to do more things with your functions than just evaluation
(like printing, symbolic differentiation), introducing a datatype is a
good idea.
Best regards,
Tom
--
.signature: Too many levels of symbolic links
More information about the Haskell
mailing list