MyNixOS website logo
Description

A comonoid w.r.t. Day.

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.

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 Monadjust 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 aa -> f a
Day f f a -> f af (f a) -> f a
Comonoid<=Comonad
f a -> af a -> a
f a -> Day f f af 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
Metadata

Version

0.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows