[Haskell-cafe] can't figure out a type
jwlato at gmail.com
Wed Feb 11 12:34:50 EST 2009
Thanks for answering. What I'm trying to do is probably very simple,
and I think the biggest problem is that I don't fully understand kinds
Here's an example instance:
instance Chunkable [a] a where
cmap = map
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
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'
On Wed, Feb 11, 2009 at 5:12 PM, Job Vranish <jvranish at gmail.com> wrote:
> What do you mean by parameterized over a different type?
> will c have a kind of * -> * ? I don't think it has to be for what you
> want to work, but the idea of "same instance" will go out the window.
> Do you have a small usage example?
> On Wed, Feb 11, 2009 at 11:52 AM, John Lato <jwlato at gmail.com> wrote:
>> I'm working on some code like the following:
>>> class Chunkable c el | c -> el where
>>> cLength :: c -> Int
>>> cHead :: c -> Maybe el
>> I want to be able to map over this type, like this:
>>> cMap :: Chunkable c' el' => (el -> el') -> c -> c'
>> but this isn't quite right. c' shouldn't be any instance of
>> Chunkable, it should be the same instance except parameterized over a
>> different type. Another approach would be something like:
>> class (Functor c) => Chunkable c el
>> except that's not right either. I think c has the wrong kind to be a
>> Functor instance.
>> I expect there's something very basic I'm missing. Could anyone point
>> in the proper direction of how to do this? Can this be expressed with
>> associated types, perhaps?
>> John Lato
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe