Deprecate Foldable for Either
rae at cs.brynmawr.edu
Fri Mar 3 17:37:28 UTC 2017
I think one of the reasons this debate continues to crop up is that there is a fundamental tension in the design of Haskell:
Haskell strives to be
a) richly typed, leading to "if it compiles, it works!"
b) as general as possible, leading to wide applicability of polymorphic functions
These two laudable goals work against each other. In many instances, we will have to choose between them, and different people will have different judgment calls.
Perhaps it would bring some of these issues into starker relief if we consider the following instance:
> instance Num Bool where
> (+) = (||)
> a - b = not (a == b)
> (*) = (&&)
> abs = id
> signum = id
> negate = not
> fromInteger 0 = False
> fromInteger _ = True
This instance is not wholly specious: it's based on well-studied Boolean algebra (at least, the definitions for (+) and (*) are), and it obeys the one documented law for Num instances. It's not fully canonical in the way that, say, the `Foldable ((,) a)` instance is, but not all instances in base are fully canonical, anyway. I venture to say it would find use in practice. But, at the same time, I imagine most Haskellers would find this instance distasteful, as it is too much in service of goal (b) and strays too far from goal (a).
About the current debate: my own tendency is to lean toward (a), but the community (now that we have FTP) appears to be drifting more toward (b). Though I see its merits -- and I take advantage of it in my own code -- I've never liked FTP and probably never will. That said, changing Either's Foldable instance to use `error` seems like unnecessary code breakage and goes against the apparent design principles at work in `base`.
But, to me, the most important aspect of a debate such as this one is that there is no one right answer, just differing viewpoints, scattered along a spectrum from (a) to (b) (surely among many other axes). We all must live with one `base`, so we all have skin in the game and the debate may be worth continuing. I just hesitate to call any comment I've seen here "wrong".
More information about the Libraries