Permalink
Browse files

Implement @paf31's comonad instances for Day

  • Loading branch information...
ekmett committed Aug 7, 2016
1 parent 2ee01b6 commit c77c6ec2180ddbd1d1bf82c308ef4a36a6702255
Showing with 13 additions and 0 deletions.
  1. +13 −0 src/Data/Functor/Day.hs
View
@@ -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
@@ -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'.
--

0 comments on commit c77c6ec

Please sign in to comment.