[Haskell] Re: Empty instance declaration

apfelmus apfelmus at quantentunnel.de
Fri Dec 28 11:12:25 EST 2007


Neil Mitchell wrote:
>> The trouble, of course, is that classes could have rather complicated
>> "minimum instance" requirements.  Still, if someone came up with a
>> decent syntax such as (but better than)
> 
> You don't need a syntax, the information is already there. You also
> don't need to do complicated non-termination analysis. Taking the
> slightly simpler example of:
> 
> class Eq a where
>    a == b = not (a /= b)
>    a /= b = not (a == b)
> 
> From this example its clear that (==) depends on (/=) and that (/=)
> depends on (==). i.e. its obvious they form a cycle.

Ah, but it's not "clear" at all :) How about something wicked like

   class UselessEq a where
      (==), (/=) :: Bool -> a -> Bool

      True  == b = b
      a     == b = not (a /= b)

      False /= b = b
      a     /= b = not (a == b)

This may be useless but I wouldn't be surprised if interesting examples 
utilizing polymorphic recursion or multi parameter type classes exist.


Regards,
apfelmus



More information about the Haskell mailing list