What is Applicative Functor definition from the category theory POV?

前端 未结 2 1327
粉色の甜心
粉色の甜心 2020-12-07 16:44

I was able to map Functor\'s definition from category theory to Haskell\'s definition in the following way: since objects of Hask are types, the functor F

2条回答
  •  没有蜡笔的小新
    2020-12-07 17:40

    You're right, Applicative translates less straightforwardly than Functor or Monad. But in essence, it is the class of monoidal functors:

    class Functor f => Monoidal f where
      pureUnit :: f ()
      fzip :: f a -> f b -> f (a,b)
    

    From that you can define – within Hask

    pure x = fmap (const x) pureUnit
    

    and

    fs <*> xs = fmap (uncurry ($)) $ fzip fs xs
    

    See this answer for a full proof that Applicative and Monoidal are really equivalent.

提交回复
热议问题