I'm fairly new to Haskell, and one thing I've been struggling with is writing readable code using records.
My specific problems are:
- I haven't found an effective strategy for dealing with name conflicts between fields in different record types. I'm finding I want the same field in multiple different record types, and the name conflict issue is really annoying. I end up choosing some prefix to put on all of my fields, which adds to verbosity and hinders readability.
- Using nested records results in really verbose code. I find
someFunction(foo.bar, 2 * foo.bar.baz)
in a language like Java or C++ to be pretty readable. In Haskell I find myself writing this to accomplish the same thing
someFunction (fooBar foo) (2 * barBaz (fooBar foo))
which is a lot harder to visually parse, and calls to functions with multiple arguments quickly become unreadable. In order to make this more readable, I find myself defining intermediate values which are to extract fields from records, which is more readable, but adds more lines of code, so it hurts readability in a different way.
Is there a better way to use records that is more readable, or is there something I should be doing instead? Just using tuples? Writing functions with tons of parameters instead of grouping related values into records? Something else?