O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The INI parser is a combinatorial top-down recursive-descent parser. Its monad instance creates a composable function that can be run later with runParser with input. We used monad/Applicative and Functor to combine the parser combinatorially from smaller units such as char, quotedchar, quotedvalue, and so on until we build the whole INI file parser.

Every time we compose two parsers, we create a function that first runs one parser, evaluates its value and remaining input, and then invokes the second parser to again evaluate its value. Such nesting and sequencing of parsers gives rise to a composition of parsing functions. The resultant parser function can be run on input to get the desirable value. 

The parser is diagrammatically ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required