| > Elm's JSON combinators are great. > I'm sure one reason so many people have particular trouble Those two sentences don't really fit together. Elm isn't an academic experiment, which means people need to use it. If the vast majority of people find it overly difficult, then it probably is. > come from a dynamically-typed language where you'd just go `user = JSON.parse(string)` Not just dynamic languages. Haskell, one of Elm's inspirations, can handle it a hell of a lot easier. Define an interface, then use it on a string: data Coord = Coord { x :: Double, y :: Double }
deriving (Show, Generic)
let req = decode "{\"x\":3.0,\"y\":-1.0}" :: Maybe Coord
I am cheating a bit, as that's the aeson package... But decoding the JSON is a lot simpler than the Elm equivalent, and Haskell doesn't even target web browsers, where JSON is so prevalent.But, here's another static example, this time, C++. auto j3 = json::parse("{ \"happy\": true, \"pi\": 3.141 }");
You can use auto to avoid writing a massive type definition, or you can write it ensure it's correct.Static typing has nothing to do with not being able to write JSON.parse(string), because it doesn't prevent that. At all. |
If that's your view then Elm's approach is a plus for the language since it eliminates a potential pitfall.