Luis Manuel O.Soares <[EMAIL PROTECTED]> writes
to: [EMAIL PROTECTED]
> [...]
> I would like a function that deals with things pretty much like
> this one:
> f ("2 + 3 * 2") = 8
The DoCon-2 program <http://haskell.org/docon/>
does the things like
let p1 = cToUPol "x" dZ 1 :: UPol Integer
in
smParse p1 "(x+2)*(x-2)"
--> x^2 - 4 :: UPol Integer
In this example, it parses a polynomial by the given sample.
It is easy to add the code which would enable this for Integer too:
smParse 0 "2 + 3 * 2" --> 8 :: Integer
Further, composing this with `show', you get
interpreter :: String -> String
In any case, this all would be much slower than the computation
with the values of the "real" algebraic types, like Integer or UPol.
But what i would like to know too:
as *any* Haskell compiler understands the programs with the
expressions like
"2 + 3 * 2",
is not it natural to provide a standard function for parsing
of such things to the value of needed type?
And what the standard provides, is only a poor `lex' function.
Do i mistake?
------------------
Sergey Mechveliani
[EMAIL PROTECTED]