Our program demonstrates how to parse numbers from strings in PureScript. Here’s the full source code and explanation:
In PureScript, we use the Data.Number and Data.Int modules for number parsing. Unlike in some other languages, PureScript’s type system and its use of Maybe make it explicit when a parsing operation might fail.
To run the program, you would typically compile it with the PureScript compiler and then run it with Node.js:
This example demonstrates how to parse various types of numbers from strings in PureScript, including floating-point numbers, integers, and hexadecimal numbers. It also shows how to handle potential parsing errors using the Maybe type.
Next, we’ll look at another common parsing task: URLs.