this post was submitted on 22 Oct 2025
        
      
      855 points (98.2% liked)
      Programmer Humor
    27113 readers
  
      
      1423 users here now
      Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
        founded 2 years ago
      
      MODERATORS
      
    you are viewing a single comment's thread
view the rest of the comments
    view the rest of the comments
 
          
          
You gotta admit though, Haskell is crazy good for parsing and marshaling data
Yes. I'm divided into "hum... 100 lines is larger than I expected" and "what did he mean 'from scratch'? did he write the parser combinators? if so, 100 lines is crazy small!"
But I'm settling in believing 80 of those lines are verbose type declarations.
You could probably write a very basic parser combinator library, enough to parse JSON, in 100 lines of Haskell
Judging by the Parser newtype, he did.
I decided to write it myself for fun. I decided that "From Scratch" means:
readfrom PreludeHere is what I came up with (using my favourite parsing method: parser combinators):
This parses numbers as my own weird
Decimaltype, in order to preserve all information (converting toDoubleis lossy). I didn't bother implementing any methods on theDecimal, because there are other libraries that do that and we're just writing a parser.It's also slow as hell but hey, that's naive implementations for you!
It ended up being 113 lines. I think I could reduce it a bit more if I was willing to sacrifice readability and/or just inline things instead of implementing stdlib typeclasses.
So, ARE you bringing a girl?
I'm not coming to my parents for this new year's because I might get arrested and/or sent to die in a war. But once Putin dies, yes, I am
Didn't know where you were talking about til you said Putin.
So that's two things to look forward to!
With recursive list comprehensions you can cram quite some complexity into one line of code.
Haskell is succinct.
Just looking at the image, yeah he's a little parser combinator library entirely from scratch.
Not sure what you mean by verbose type declarations. It looks to be 2 type declarations in a few lines of code (a newtype for the parser and a sum type to represent the different types of JSON values). It's really not much at all.
serde has entered the chat
From Scratch (as much as I like Rust, it's very likely more verbose from scratch). Haskell is perfect for these kinds of things.
I will concede that implementing the first version in Haskell would be better.
Mostly so that we can then fulfil the meme of reimplementing it in Rust!
Personally I'm more partial to nom. Serde is quite verbose and complex for a parser.