The story with data-default
haskellPublished on May 30, 2020
Using data-default
or
data-default-class
in Haskell is always a mistake.
Why?
-
It adds no value. For simple types like
Int
orBool
there is no universal default value because the concepts they represent are too general. For more complex and specific types nothing beats a simple non-polymorphic value. Such a value can also build on other non-polymorphic values. -
It makes incorrect code typecheck. When you have your defaults as non-polymorphic values, every time you use a default you are being explicit about the type you mean. With
def
, as long as you happen to put it in a place where GHC expects something that happens to have aDefault
instance it will be happily accepted. It does not help thatDefault
has instances likeDefault r => Default (e -> r)
. -
There may be more than one default value per type.
-
It is an extra dependency. However light, no dependency is better than one.
-
The last commit was in 2016.