Frege / frege

Frege is a Haskell for the JVM. It brings purely functional programing to the Java platform.
https://github.com/Frege/frege/wiki/_pages
Other
3.64k stars 145 forks source link

String to Number conversion #147

Closed Dierk closed 9 years ago

Dierk commented 9 years ago

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.

mmhelloworld commented 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
Dierk commented 9 years ago

ah - ok, thanks.

Ingo60 commented 9 years ago

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.