[Haskell-cafe] RE: can't figure out a type

Brian Bloniarz phunge0 at hotmail.com
Wed Feb 11 15:22:24 EST 2009


Hi John,



> In the class I wrote, c has kind * (e.g. [a]), but then I don't see
> how to write a suitable map function.  For that, I would want c to
> have kind * -> *.  Unfortunately then I don't know to write the
> others.
> 
> Would I have to do something with c having kind (* -> *) ?
> 
> class Chunkable2 c el where
>    cLength :: c el -> Int
>    cHead :: c el -> Maybe el
>    cMap :: (el -> el') -> c el -> c el'

When c is (* -> *), why do you need el to be a parameter of the

typeclass at all? I.e., would this work for your purposes:



> class Chunkable3 c where

>   cLength :: c el -> Int

>   cHead :: c el -> Maybe el

>   cMap :: (a -> b) -> c a -> c b



> instance Chunkable3 [] where

>     cLength = length

>     cMap = map
>     cHead = ...

Using Functor as a superclass of Chunkable3 works too.



Thanks,

-Brian
_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090211/059ce740/attachment.htm


More information about the Haskell-Cafe mailing list