Search code examples
javahaskellconvertersoption-typefrege

In Frege how can I convert an String safely to a Maybe Int?


In Frege I want to convert an String to an Int, but need to handle unparsable strings too.

So I guess I'm looking for something like a readMaybe function. Where do I find this? Or how can I use Java's parseInt and catch the exception in Frege?


Solution

  • In Frege, it's as simple as:

    myStr.double
    

    which returns an Either.

    (Found this in the Frege Translation of "Learn You a Haskell for Great Good!.")