Luis Manuel O.Soares wrote:
> Is there any function that takes a String as an argument and returns a
> numeral??
Andy Gill wrote:
There is no built in function that does what you want.
But there _is_ a built in function that does what he _asked for_.
If s is a string of the form
- zero or more layout characters
- optional sign
- one or more digits
- zero or more layout characters
then read s will do the job perfectly. Example:
% hugs
-- banner deleted
Prelude> (read " -2 ") :: Int
-2
There _is_ some reflective capability in Haskell.
Via the 'deriving Read, Show' mechanism you can automatically
get a parser (read and its relatives) and unparser (show and its
relatives) for *data structures*. Not for expressions in general,
admittedly.
The Haskell documentation includes a fairly detailed description
of how read works, and for a simple expression language it's dead
simple to copy that model.