[Haskell-cafe] A type class puzzle

Arie Peterson ariep at xs4all.nl
Tue Oct 31 15:53:15 EST 2006

Greg Buchholz wrote:

> ...That first article is the strangest.  I couldn't reconcile the fact
> that if our type signature specifies two arguments, we can pattern
> match on three arguments in the function definition.  Compare the number
> of arguments in the first and second instances...
>> class BuildList a r  | r-> a where
>>     build' :: [a] -> a -> r
>> instance BuildList a [a] where
>>     build' l x = reverse$ x:l
>> instance BuildList a r => BuildList a (a->r) where
>>     build' l x y = build'(x:l) y

I'm not sure I'm getting your point, but this is just because in the
second instance, the second parameter of BuildList is 'a -> r', so the
specific type of 'build\'' is '[a] -> a -> (a -> r)' which is just '[a] ->
a -> a -> r' (currying at work).



More information about the Haskell-Cafe mailing list