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

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Tue Jul 14 01:12:39 EDT 2009


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 at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20090714/9c80fff1/PGP.bin


More information about the Beginners mailing list