ekmett / kan-extensions

Kan extensions, Kan lifts, the Yoneda lemma, and (co)monads generated by a functor
Other
78 stars 33 forks source link

Instances for Codensity (Semigroup, Monoid, numeric classes) #37

Open Icelandjack opened 7 years ago

Icelandjack commented 7 years ago

There are some trivial instances for Managed that could be implemented for Codensity, the Monoid instance is put to good use by Gabriel Gonzales in his Applied category theory and abstract algebra talk

instance Semigroup a => Semigroup (Codensity m a) where
  (<>) = liftA2 (<>)

instance Monoid a => Monoid (Codensity m a) where
  mempty = pure mempty

#if !(MIN_VERSION_base(5,0,0))
  mappend = liftA2 (<>)
#endif

Same with Num, Fractional, Floating.

Atry commented 4 years ago

Why not use Ap (Codensity m) a instead? https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Monoid.html#t:Ap