Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

instance Applicative f => Applicative (Density f) and platform compat…

…ibility patch
  • Loading branch information...
commit 3fd3bccb56c36189fa73006b1f38b77d845d151e 1 parent 722038a
@ekmett authored
Showing with 22 additions and 11 deletions.
  1. +15 −4 Control/Comonad/Density.hs
  2. +7 −7 kan-extensions.cabal
View
19 Control/Comonad/Density.hs
@@ -10,8 +10,8 @@
-- Portability : non-portable (GADTs, MPTCs)
--
-- The density comonad for a functor. aka the comonad generated by a functor
--- The ''density'' term dates back to Dubuc''s 1974 thesis. The term
--- ''monad genererated by a functor'' dates back to 1972 in Street''s
+-- The ''density'' term dates back to Dubuc''s 1974 thesis. The term
+-- ''monad genererated by a functor'' dates back to 1972 in Street''s
-- ''Formal Theory of Monads''.
----------------------------------------------------------------------------
module Control.Comonad.Density
@@ -20,8 +20,10 @@ module Control.Comonad.Density
, densityToAdjunction, adjunctionToDensity
) where
+import Control.Applicative
import Control.Comonad
import Control.Comonad.Trans.Class
+import Data.Functor.Apply
import Data.Functor.Adjunction
data Density k a where
@@ -38,10 +40,19 @@ instance Comonad (Density f) where
instance ComonadTrans Density where
lower (Density f c) = extend f c
-
+
+instance Apply f => Apply (Density f) where
+ Density kxf x <.> Density kya y =
+ Density (\k -> kxf (fmap fst k) (kya (fmap snd k))) ((,) <$> x <.> y)
+
+instance Applicative f => Applicative (Density f) where
+ pure a = Density (const a) (pure ())
+ Density kxf x <*> Density kya y =
+ Density (\k -> kxf (fmap fst k) (kya (fmap snd k))) (liftA2 (,) x y)
+
-- | The natural isomorphism between a comonad w and the comonad generated by w (forwards).
liftDensity :: Comonad w => w a -> Density w a
-liftDensity = Density extract
+liftDensity = Density extract
densityToAdjunction :: Adjunction f g => Density f a -> f (g a)
densityToAdjunction (Density f v) = fmap (leftAdjunct f) v
View
14 kan-extensions.cabal
@@ -1,6 +1,6 @@
name: kan-extensions
category: Data Structures, Monads, Comonads, Functors
-version: 2.2
+version: 2.3
license: BSD3
cabal-version: >= 1.6
license-file: LICENSE
@@ -33,17 +33,17 @@ library
base >= 4 && < 5,
comonad >= 1.1.1.3 && < 1.2,
containers >= 0.4 && < 0.5,
- transformers >= 0.3 && < 0.4,
- mtl >= 2.1 && < 2.2,
- semigroupoids >= 1.3 && < 1.4,
+ transformers >= 0.2 && < 0.4,
+ mtl >= 2.0.1 && < 2.2,
+ semigroupoids >= 1.3.1 && < 1.4,
contravariant >= 0.2.0.1 && < 0.3,
- distributive >= 0.2.1 && < 0.3,
+ distributive >= 0.2.2 && < 0.3,
comonad-transformers >= 2.1 && < 2.2,
comonads-fd >= 2.1 && < 2.2,
keys >= 2.1.3 && < 2.2,
free >= 2.1 && < 2.2,
- adjunctions >= 2.2 && < 2.3,
- representable-functors >= 2.2 && < 2.3,
+ adjunctions >= 2.2.1.1 && < 2.3,
+ representable-functors >= 2.2.1.1 && < 2.3,
speculation >= 1.4.1 && < 1.5
exposed-modules:
Please sign in to comment.
Something went wrong with that request. Please try again.