4 ms·
I remember I did an Advent of Code day 1 in Haskell a while back. The meat of the code was a one liner. But opening a file, throwing away the first line and pa
by djtango 1y ago
I remember I did an Advent of Code day 1 in Haskell a while back.
The meat of the code was a one liner. But opening a file, throwing away the first line and parsing a CSV took a lot more head scratching, especially if you've only ever done puzzles in Haskell.
Makes the hard things easy and the easy things hard
- ngruhn 1y agoSame. Until I discovered those parser combinator libraries which are THE way to do parsing in Haskell. It makes parsing so pleasant you'll never need a regex again. A parser for that CSV file probably looks like this: line = decimal `sepBy` char ',' file = line `sepBy` newline That's it. It almost reads like prose.
- djtango 1y agoThanks for sharing! This was in a pre-LLM era and I couldn't be bothered to research the right way to do this. Those parser combinators are excellent, so clean
- rafram 1y agoThat wouldn’t be a very good CSV parser.
- Tainnor 1y agoIt doesn't have to be a general purpose CSV parser, it just has to be able to parse the specific AoC input
- nh23423fefe 1y ago<input runhaskell -e 'interact (oneliner . parse . drop 1 . lines)'