[Haskell-cafe] Restricted type classes

Ben Millwood haskell at benmachine.co.uk
Sat Sep 4 13:14:01 EDT 2010

I have only one thing to add to this discussion:

On Fri, Sep 3, 2010 at 5:16 AM, Ivan Lazar Miljenovic
<ivan.miljenovic at gmail.com> wrote:
> 2b) Is it OK to promote functions that use a class to being class
> methods?  When I was discussing this in #haskell several people
> mentioned that defining something like liftA2 for the Set instance of
> (restricted) Applicative would make more sense than the default <*>
> (since (a -> b) isnt' an instance of Ord).

One problem with defining both <*> and liftA2 in the class in terms of
each other is that omitting them from instances is no longer a
compile-time error, nor is it even an obvious runtime error - it's
frequently an infinite loop, which is unpleasant. Though I understand
that it's nice to be able to choose the methods you want to define, I
think static error detection is nice too, so I tend to avoid providing
extra class methods with defaults unless the alternative is much

On that note, why *do* we have missing instance methods filled in with
bottoms, so that even without defaults, it's a warning rather than an
error? It seems like quite an un-Haskelly thing to do. I know there
may be some cases where you do not need to define a particular method,
but imo you should be required to explicitly opt out of it if that's
the case.

More information about the Haskell-Cafe mailing list