Posts

Showing posts from August, 2014

Field Accessors Considered Harmful

It's pretty well known these days that Haskell's field accessors are rather cumbersome syntactically and not composable.  The lens abstraction that has gotten much more popular recently (thanks in part to Edward Kmett's lens package) solves these problems.  But I recently ran into a bigger problem with field accessors that I had not thought about before.  Consider the following scenario.  You have a package with code something like this: data Config = Config { configFieldA :: [Text] } So your Config data structure gives your users getters and setters for field A (and any other fields you might have).  Your users are happy and life is good.  Then one day you decide to add a new feature and that feature requires expanding and restructuring Config.  Now you have this: data MConfig = MConfig { mconfigFieldA :: [Text] } data Config = Config { configMC :: MConfig , configFieldX :: Text , configFieldY :: Bool }...