Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm not so sure whether this is truly a benefit of FP. Is it the same in languages like haskell or ocaml? (haven't used them in any significant way)

As for clojure, it's described as a "data-driven programming", which is almost as important as it's FP designation. I think it's that data-driven part that brings a lot of the benefits you're talking about.



Yes, smooth sailing in Haskell.

Define the datatype and let GHC generics and the Aeson library handle the rest.

The worst-case scenario is when keys in your JSON conflict with keywords or existing functions: 'id' and 'data' are pretty common. It means you need to rename your datatype fields to something like '_id' and '_data', and provide a mapping function to Aeson.

Where the 'fully automatic' declaration looks like:

    instance FromJSON Coord
The declaration where you remap to avoid name clashes could look like:

    instance FromJSON Coord where
        parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = dropWhile (=='_') }


> I'm not so sure whether this is truly a benefit of FP.

Yeah, it is not. But like pure functions (that are also not necessary something from FP, you can have pure functions in probably any language out there), it is easier to apply in FP and also more idiomatic there.

Like, you can simply generate a map or dict in most languages and have it transformed and converted in most languages out there, but once things gets complicated probably someone somewhere will say in a Pull Request "this is not the idiomatic way in OOP, you should create a data object and store this data there" and blah blah blah. FP doesn't have this kinda of baggage.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: