Building a Monadic Parser

Monadic parsers are a common pattern in Haskell applications. The term monadic in a monadic parser is a little bit misleading, because as you’ll see later on in this chapter, a lot of the benefit from this style of parsing comes from its Applicative instance, rather than its Monad instance. Still, creating a Parser monad allows users of our library to use the familiar do notation.

To get an idea of where we’re going and what this will look like in practice, let’s start with a short demo of what it will look like to decode the values that we encoded in testEncodeValue earlier:

 testDecodeValue
  :: ​ByteString
  -> ​Either​ ​String
  ( ​FileData​ ​String
  , ​FileData​ [​Text​]
  , ​FileData​ (​Word32​,​String​)

Get Effective Haskell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.