[Haskell-cafe] Having a connection between kind * and kind * -> *
Miguel Mitrofanov
miguelimo38 at yandex.ru
Thu Aug 19 09:33:04 EDT 2010
Ivan Lazar Miljenovic wrote:
> I'm trying to update container-classes to duplicate the pre-existing
> classes defined in the Prelude (Functor, etc.) and am trying to get my
> approach on how to have functions/classes that work on types of kind *
> (e.g. Bytestring) as well as kind * -> * (e.g. lists), as my previous
> approach didn't work.
>
> To define the connection, I've copied the style set out by Ganesh's
> rmonad ( http://hackage.haskell.org/package/rmonad ) package:
>
> ,----
> | -- | Indicates what kind of value may be stored within a type. Once
> | -- superclass constraints are available, the @v@ parameter will
> | -- become an associated type.
The comment above tells enough.
> | class Stores c v | c -> v
> |
> | data family Constraints :: (* -> *) -> * -> *
> |
> | class (Stores (c v) v) => Suitable c v where
> | constraints :: Constraints c v
> `----
>
> This works. However, what doesn't work is when I try to use these
> classes to re-define Functor:
>
> ,----
> | class (Stores c v) => Mappable c v where
And where is functional dependency?
> | rigidMap :: (v -> v) -> c -> c
> |
> | class (Mappable (c v) v) => Functor c where
> | fmap :: (Suitable c a, Suitable c b) => (a -> b) -> c a -> c b
> `----
>
> GHC doesn't like this definition of Functor; the only way to get it to
> work is to make `v' a parameter of the Functor class as well, even
> though it doesn't actually get used.
>
> Why is this? Is there any way around it?
>
> (Limitations like this are making me more and more consider dumping this
> whole concept as it's just becoming a pain, but more importantly rather
> boring :s)
>
More information about the Haskell-Cafe
mailing list