Hacker News new | ask | show | jobs
by ronjouch 3441 days ago
If you (or other passersby) have experience in how JSON decoding is achieved in Haskell (or other statically-typed functional languages), I'd be curious to read some sort of comparison with Elm.

A quick Googling suggests Data.Aeson [1] is the popular library in Haskell land. Does it rank better on what I was hoping for (succinctness, ease of use)? If yes, would it be reachable within Elm, or are some Haskell constructs missing in Elm to achieve a similar experience?

[1] https://hackage.haskell.org/package/aeson-0.6.1.0/docs/Data-...

2 comments

Wasn't quite ready to release this, but it seems relevant so see part two here:

https://github.com/codygman/concise-json-parsing-in-haskell/...

Please give feedback if you don't mind. I'd also like to wait a bit before officially sharing with wider audiences then this comment gets.

Keep in mind that part one is "haskell/lens as explicit as possible" which is why I suggested looking at part two to draw conclusions.

Edit: just looked at elm decoder pipeline and it looks very similar to aeson.

Current version: https://hackage.haskell.org/package/aeson-1.1.0.0/docs/Data-...

The key difference with Aeson is this line:

> deriving (Generic, Show)

Because of this, it's not necessary in that example to even write the JSON decoder manually. The compiler can generate it on its own. I don't personally know of any way to achieve this in Elm, as Elm doesn't have typeclasses and what's effectively happening here is that an instance of the FromJSON typeclass is being computed by the compiler.

A very similar trick is possible in PureScript:

http://www.purescript.org/learn/generic/