3 ms·
These days megaparsec might be a better way to get started as it has built on Parsec to improve the speed and documentation. https://markkarpov.com/tutorial/m
by massysett 4y ago
These days megaparsec might be a better way to get started as it has built on Parsec to improve the speed and documentation.
https://markkarpov.com/tutorial/megaparsec.html https://markkarpov.com/tutorial/megaparsec.html
https://hackage.haskell.org/package/megaparsec https://hackage.haskell.org/package/megaparsec
However it does rely on some GHC extensions, which makes things a bit more complicated for beginners, so for simplicity's sake it might be easier to start with Parsec and one of the old papers that goes with it.
- sondr3 4y agoIt doesn't need any extensions to work, the only reason `OverloadedStrings` is enabled in the tutorial is because the parser uses `Text` over `String` to parse the input.
- johnday 4y agoIn fact, I would recommend against enabling OverloadedStrings while writing parsers, since it can be confusing. Some bright spark added an IsString instance for IsString a => Parser a, meaning that "Hello" is a parser for the string "Hello". It also means that `many "Hello"` will parse "HelloHelloHello", which is kinda cool but confusing for a beginner.
- massysett 4y agoFrom Text.Megaparsec: {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE Safe #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} And you do have to understand TypeFamilies to use Megaparsec.
- simonmic 4y agoNo you don't.
- nimih 4y ago> And you do have to understand TypeFamilies to use Megaparsec. This is only the case if you're using custom input streams, right? Writing a parser that just operates on ByteString/Text seems like a pretty gentle/reasonable introduction to this style of parsing and doesn't require any understanding of TypeFamilies as far as I can tell (I certainly didn't understand TypeFamilies when I learned to use megaparsec).
- massysett 4y agoThe types of many basic and essential functions, including ‘satisfy’ and ‘token’, use type families with associated types, but yes, it is possible to use megaparsec without actually understanding the types.