Join Newsletter

Just Parsing Through

YOW! Lambda Jam 2019 - 14 May

SETUP - You should have a basic understanding of Haskell (what data types, functions and type classes are) and have a working GHC installation. Clone and build these exercises

The default tool that many programmers immediately reach for when they wish to parse data (but don't want to deal with tools like Lex and Yacc) is regular expressions.

Of course, whenever you mention regular expressions, someone will bring up Jamie Zawinski. And now you have two problems.

However, regular expressions have many problems:

  • They aren't composable
  • They're typically represented as Strings rather than code making them harder to debug
  • Often only interpreted at runtime leading to runtime failures (no static type checking!)
  • They can't be used to parse HTML

The preferred approach in functional programming languages (also available in non-functional languages as well!) is parser combinators, which provide a way of writing your parser in code, thus being able to use all your existing tooling to do so.

In this workshop we will build up our own Parser Combinator library from scratch (and hopefully make sense of the dreaded M-word whilst we're at it!) and improve upon it, to see that there is nothing mystical about parsing in data.

Ivan Lazar Miljenovic

Sr. Developer

Standard Chartered Bank

Graphs. Haskell.  Data processing.

Workshop Details

Target Audience
Beginner to intermediate level developers that want to know how to write and use parser combinators.
Level
Intermediate
Duration
1 hour 30min

Learning Outcomes

  • Understand how parser combinators work
  • Be able to use parser combinator libraries
  • Gain an appreciation for the Functor/Applicative/Monad typeclasses

Workshop Outline

  • Write a basic parser from scratch (with motivating examples)
    • This includes covering the Functor/Applicative/Monad (+Alternative) hierarchy
  • Investigate how to optimise it:
    • Better error messages
    • Alternative implementations

Prerequisites

You should have a basic understanding of Haskell (what data types, functions and type classes are) and have a working GHC installation. Clone and build these exercises

(You can use another language other than Haskell if you prefer, but I may not be able to assist you if you run into any problems.)