day-comonoid: A comonoid w.r.t. Day

[ bsd3, comonads, data-structures, functors, library ] [ Propose Tags ]

A type class Comonoid to represend a comonoid w.r.t. Day, just like Applicative is a type class of monoid w.r.t. Day. See README.md for more information.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1
Change log CHANGELOG.md
Dependencies base (>=4.10 && <5), comonad (>=5.0.8 && <5.1), kan-extensions (>=5 && <5.3) [details]
License BSD-3-Clause
Copyright Koji Miyazato
Author Koji Miyazato
Maintainer viercc@gmail.com
Category Data Structures, Comonads, Functors
Home page https://github.com/viercc/functor-monad/tree/main/day-comonoid
Uploaded by viercc at 2023-10-15T06:35:06Z
Distributions NixOS:0.1
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 21 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-10-15 [all 1 reports]

Readme for day-comonoid-0.1

[back to package description]

day-comonid: The(?) dual of Applicative

This package provides a type class named Comonoid.

class Comonad f => Comonoid f where
    coapply :: f a -> Day f f a

The name "Comonoid" should be read in a context. A functor f being Comonoid means it's a comonoid in the category of Functors equipped with Day as its tensor product.

Comonoid can be contrasted with Applicative, which is equivalent to a type class for monoids in the said category of Functors.

class Functor f => Applicative f where
    pure  :: a -> f a
    (<*>) :: f (a -> b) -> f a -> f b

-- A hypothetical type class equivalent to Applicative
class Functor f => DayMonoid f where
    pure' :: Identity a -> f a
    default pure' :: Applicative f => Identity a -> f a
    pure' = pure . runIdentity

    ap' :: Day f f a -> f a
    default ap' :: Applicative f => Day f f a -> f a
    ap' = dap

Comonoid is related to Comonad, just like Applicative is related to Monad.

Applicative is a superclass of Monad just because any Monad f instance is sufficient to implement Applicative f in a certain way.

Similarly, Comonad is a superclass of Comonoid, just because having (extract :: f a -> a) and coapply is sufficient to make f a Comonad.

Applicative => Monad
a -> f a a -> f a
Day f f a -> f a f (f a) -> f a
Comonoid <= Comonad
f a -> a f a -> a
f a -> Day f f a f a -> f (f a)

Both of these relations are rooted in the same fact that the following conversion is possible for any Functor f and Functor g:

dayToCompose :: (Functor f, Functor g) => Day f g a -> f (g a)
dayToCompose (Day fb fc op) = fmap (\b -> fmap (op b) fc) fb