
I wrote:
You don't need the added complexity of a type class for this - just define the default value.
Michael Snoyman wrote:
I don't think it's a case of necessity. It just happens to be very convenient to be able to use the three letters "def" instead of "defaultFrobnicatorSettings" or something like that.
You can use whatever name you'd like for a default value, short or descriptive. Type classes are a beautiful and powerful technique in Haskell, but they do add some underlying complexity to your types. In my experience, when building and maintaining large code bases in Haskell, things are much easier when you limit the use of type classes to when they are really needed. I create type classes when I need non-trivial polymorphism. Even then, I often prefer simpler techniques such as data types with parameters or passing functions as parameters. There are also advanced techniques using type classes which are needed for building some kinds of libraries. In particular, I have come to the conclusion that type classes are not a good tool for simple namespace control in a typical Haskell program. It is a common mistake for beginners who come to Haskell with a background in OOP to massively overuse type classes. Style is a matter of taste, of course. But much of the power and beauty of Haskell lies away from type classes, and it's a shame to miss out on it. So I think it is important for beginners, especially when coming from OOP, to start out by avoiding defining type classes whenever there is a good alternative (i.e. almost always). Regards, Yitz