turanct / parser-combinators-from-scratch

👨‍🏫 Trying to understand parser combinators by writing them from scratch
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

I think you can replace this with a State monad #1

Open mathiasverraes opened 4 years ago

mathiasverraes commented 4 years ago

https://github.com/turanct/parser-combinators-from-scratch/blob/cd2087d61a7efd7ed4afbba3dffd554faea67d00/src/Parser.hs#L3

... at least this worked in my own attempt:

type Parser parsed = StateT Input (Either Error) parsed
parse = runStateT
turanct commented 4 years ago

Yes! as far as i understood from the "real" libraries like parsec et al, the monad instances they made for this are (almost) like this, but with some bells and whistles.

For the meetup I wanted to keep it as simple as possible, but I guess that would've been the more Haskelly way to do it indeed!