
31 Oct
2006
31 Oct
'06
3:53 p.m.
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). Regards, Arie