Skip to content

Commit

Permalink
Implement @paf31's comonad instances for Day
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmett committed Aug 7, 2016
1 parent 2ee01b6 commit c77c6ec
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Data/Functor/Day.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Data.Functor.Day
) where

import Control.Applicative
import Control.Comonad
import Data.Distributive
import Data.Functor.Identity
import Data.Functor.Rep
Expand Down Expand Up @@ -91,6 +92,18 @@ instance (Representable f, Representable g) => Representable (Day f g) where
tabulate f = Day (tabulate id) (tabulate id) (curry f)
index (Day m n o) (x,y) = o (index m x) (index n y)

instance (Comonad f, Comonad g) => Comonad (Day f g) where
extract (Day fb gc bca) = bca (extract fb) (extract gc)
duplicate (Day fb gc bca) = Day (duplicate fb) (duplicate gc) (\fb' gc' -> Day fb' gc' bca)

instance (ComonadApply f, ComonadApply g) => ComonadApply (Day f g) where
Day fa fb u <@> Day gc gd v =
Day ((,) <$> fa <@> gc) ((,) <$> fb <@> gd)
(\(a,c) (b,d) -> u a b (v c d))

instance ComonadTrans (Day f) where
lower (Day fb gc bca) = bca (extract fb) <$> gc

-- | Day convolution provides a monoidal product. The associativity
-- of this monoid is witnessed by 'assoc' and 'disassoc'.
--
Expand Down

0 comments on commit c77c6ec

Please sign in to comment.