Functors and Applicatives for types of kind (* -> *) -> *

安稳与你 提交于 2019-12-04 22:28:50

The HFunctor I tend to think of is (* -> *) -> * -> * -- i.e. a legitimate functor on functors. This has different characteristics than the one you're thinking of.

Here's how to define it, as well as the "monoidal" version of an applicative on it.

type Nat f g = forall a. f a -> g a

class HFunctor (f :: (* -> *) -> * -> *) where
    hfmap :: (Nat g h) -> Nat (f g) (f h)

data Prod f g a = Prod (f a) (g a)

class HFunctor f => HApplicative f where
    hpure  :: Nat g (f g)
    htensor :: Nat (Prod (f g) (f h)) (f (Prod g h))

I'll try to update later with some ideas about what this is and how to use it.

This isn't exactly what you're asking for, I realize, but I was inspired to try it out by your post.

I'd be interested in your specific use case as well.

To your two specific questions A) The HFunctor you describe has been described before on various occasions, I think by Gibbons in particular, but I don't know of it packaged up. I certainly haven't seen the Applicative before. B) I think you're stuck with the wrapper because we can't partially apply type synonyms.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!