Closed Dierk closed 9 years ago
The conversion functions are already there in PreludeBase.
frege> "23".int
:: (NumberFormatException | Int)
frege> either (const 0) id "23".int
23
frege> either (const 0) id "23".double
23.0
frege> either (const 0) id "23".integer
23
ah - ok, thanks.
Yeah, this is a point we should stress in beginners tutorials. I never felt easy with implementing read .... it is supposed to be a pure function, but as such you can't act on errors. But this is crucial, for example when you get something via the command-line.
The current Prelude provides no means to read a number like 123 from a string like "123".
One solution would be to make Int, Integer, and Double instances of ReadS.