Skip to content

Commit c77c6ec

Browse files
committed
Implement @paf31's comonad instances for Day
1 parent 2ee01b6 commit c77c6ec

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Data/Functor/Day.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module Data.Functor.Day
3838
) where
3939

4040
import Control.Applicative
41+
import Control.Comonad
4142
import Data.Distributive
4243
import Data.Functor.Identity
4344
import Data.Functor.Rep
@@ -91,6 +92,18 @@ instance (Representable f, Representable g) => Representable (Day f g) where
9192
tabulate f = Day (tabulate id) (tabulate id) (curry f)
9293
index (Day m n o) (x,y) = o (index m x) (index n y)
9394

95+
instance (Comonad f, Comonad g) => Comonad (Day f g) where
96+
extract (Day fb gc bca) = bca (extract fb) (extract gc)
97+
duplicate (Day fb gc bca) = Day (duplicate fb) (duplicate gc) (\fb' gc' -> Day fb' gc' bca)
98+
99+
instance (ComonadApply f, ComonadApply g) => ComonadApply (Day f g) where
100+
Day fa fb u <@> Day gc gd v =
101+
Day ((,) <$> fa <@> gc) ((,) <$> fb <@> gd)
102+
(\(a,c) (b,d) -> u a b (v c d))
103+
104+
instance ComonadTrans (Day f) where
105+
lower (Day fb gc bca) = bca (extract fb) <$> gc
106+
94107
-- | Day convolution provides a monoidal product. The associativity
95108
-- of this monoid is witnessed by 'assoc' and 'disassoc'.
96109
--

0 commit comments

Comments
 (0)