[Haskell-cafe] Specializing classes with classes

Jake McArthur jake.mcarthur at gmail.com
Sat Dec 29 22:43:36 EST 2007

On Dec 28, 2007, at 10:18 PM, ajb at spamcop.net wrote:

> Quoting alex <maskif at yahoo.com.au>:
>> I would like to do this:
>>    class Foo t where
>>        hi :: t -> Bool
>>    class Foo t => Bar t where
>>        hi x = True
> This is arguably one of the most requested features in Haskell.  The  
> only
> reason why it hasn't been implemented yet is that some of the corner  
> cases
> are a little subtle.

Really? This code doesn't even really make any sense to me. In order  
to be an instance of Bar, t has to already be an instance of Foo,  
implying that the function hi is already defined for t. What would the  
function in this example do?

      instance Foo Wibble where
          hi x = False

      instance Bar Wibble

      myFunc :: Wibble -> Bool
      myFunc x = hi x

More information about the Haskell-Cafe mailing list