Data Constructors and Readability
Thursday, February 5th, 2009I think I’ve put my finger on one reason I’m finding Haskell hard to read. Consider this algebraic data type definition from Real World Haskell:
data Doc = Empty | Char Char | Text String | Line | Concat Doc Doc | Union Doc Doc deriving (Show, Eq)
There’s no distinction between the value constructor and the components of the type. This is especially critical when the constructor and the components have the same name as in the Char
constructor above. It also doesn’t help that they have the same naming convention (mixed camel case, initial uppercase letter).
A Java class with multiple factory methods or multiple constructors would be much more verbose, but much more readable. Humans need redundancy, even if it’s logically superfluous.
I suspect a language that retained Haskell’s semantics, but completely replaced the syntax with something more usable, legible, and familiar would have a much greater chance of success.