
Could you please elaborate on how does the constraint (ListConcat xs
ys zs) makes the instance ListConcat (x ::: xs) ys (x ::: zs)
recursive.
Also, I am interested to learn more about various ways to constrain
type classes parameters, is there a paper you would recommend?
Thanks
On Tue, Jul 14, 2009 at 1:12 AM, Brandon S. Allbery
KF8NH
On Jul 13, 2009, at 23:43 , MH wrote:
class ListConcat a1 a2 a | a1 a2 -> a where listConcat :: a1 -> a2 -> a
instance ListConcat Nil a a where listConcat = _|_
instance (ListConcat xs ys zs) => ListConcat (x ::: xs) ys (x ::: zs) where listConcat = _|_
1. How does the last function becomes recursive? 2. Why do we need constraint '(ListConcat xs ys zs) =>' ?
Your second question is the answer to the first.
3. I assume that listConcat function takes three arguments but from example provided, it takes two (see below):
The last type in the (->) chain is the return type, not an argument.
4. Does the functional dependency sign (->) implies that the last argument is the return type?
No, it says type a (which is designated as the return type by the definition of listConcat) is uniquely determined by the pair of argument types a1, a2 taken together. (That is, any given unique combination of argument types produces a unique result type.)
-- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH