[Haskell-beginners] type class question from MReader #8

Brent Yorgey byorgey at seas.upenn.edu
Fri Jul 17 10:19:24 EDT 2009


On Tue, Jul 14, 2009 at 10:05:03AM -0400, MH wrote:
> Could you please elaborate on how does the constraint (ListConcat xs
> ys zs) makes the instance ListConcat (x ::: xs) ys (x ::: zs)
> recursive.

> >> instance (ListConcat xs ys zs)
> >>             => ListConcat (x ::: xs) ys (x ::: zs) where listConcat = _|_

This says that '(x ::: xs) ys (x ::: zs)' is an instance of ListConcat
*if* 'xs ys zs' is.  So you can think of the 'ListConcat xs ys zs'
constraint as a recursive call made by 'ListConcat (x ::: xs) ys (x
::: zs)'.  As a Haskell function we might write it something like
this:

  isListConcatInstance (x ::: xs) ys (z ::: zs) = x == z && isListConcatInstance xs ys zs

Does that help?

-Brent


More information about the Beginners mailing list