comonad 0.6.0 → 0.6.1
raw patch · 2 files changed
+58/−45 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Comonad: instance Typeable1 w => Typeable2 (Cokleisli w)
Files
- Control/Comonad.hs +57/−44
- comonad.cabal +1/−1
Control/Comonad.hs view
@@ -9,7 +9,7 @@ -- Stability : provisional -- Portability : portable ----- A 'Comonad' is the categorical dual of a 'Monad'.+-- $definition ---------------------------------------------------------------------------- module Control.Comonad ( -- * Comonads@@ -33,53 +33,12 @@ import Control.Monad.Trans.Identity import Data.Functor.Identity import Data.Monoid+import Data.Typeable infixl 1 =>> infixr 1 <<=, =<=, =>= -{- |--There are two ways to define a comonad:--I. Provide definitions for 'extract' and 'extend'-satisfying these laws:--> extend extract = id-> extract . extend f = f-> extend f . extend g = extend (f . extend g)--In this case, you may simply set 'fmap' = 'liftW'.--These laws are directly analogous to the laws for monads-and perhaps can be made clearer by viewing them as laws stating-that Cokleisli composition must be associative, and has extract for-a unit:--> f =>= extract = f-> extract =>= f = f-> (f =>= g) =>= h = f =>= (g =>= h)--II. Alternately, you may choose to provide definitions for 'fmap',-'extract', and 'duplicate' satisfying these laws:--> extract . duplicate = id-> fmap extract . duplicate = id-> duplicate . duplicate = fmap duplicate . duplicate--In this case you may not rely on the ability to define 'fmap' in -terms of 'liftW'.--You may of course, choose to define both 'duplicate' /and/ 'extend'. -In that case you must also satisfy these laws:--> extend f = fmap f . duplicate-> duplicate = extend id-> fmap f = extend (f . extract)--These are the default definitions of 'extend' and'duplicate' and -the definition of 'liftW' respectively.---}+{- | $definition -} class Functor w => Comonad w where -- | @@ -165,6 +124,15 @@ -- | The 'Cokleisli' 'Arrow's of a given 'Comonad' newtype Cokleisli w a b = Cokleisli { runCokleisli :: w a -> b } +instance Typeable1 w => Typeable2 (Cokleisli w) where+ typeOf2 twab = mkTyConApp cokleisliTyCon [typeOf1 (wa twab)]+ where wa :: Cokleisli w a b -> w a+ wa = undefined++cokleisliTyCon :: TyCon+cokleisliTyCon = mkTyCon "Control.Comonad.Cokleisli"+{-# NOINLINE cokleisliTyCon #-}+ instance Comonad w => Category (Cokleisli w) where id = Cokleisli extract Cokleisli f . Cokleisli g = Cokleisli (f =<= g)@@ -194,4 +162,49 @@ instance Monad (Cokleisli w a) where return = Cokleisli . const Cokleisli k >>= f = Cokleisli $ \w -> runCokleisli (f (k w)) w+++{- $definition++There are two ways to define a comonad:++I. Provide definitions for 'extract' and 'extend'+satisfying these laws:++> extend extract = id+> extract . extend f = f+> extend f . extend g = extend (f . extend g)++In this case, you may simply set 'fmap' = 'liftW'.++These laws are directly analogous to the laws for monads+and perhaps can be made clearer by viewing them as laws stating+that Cokleisli composition must be associative, and has extract for+a unit:++> f =>= extract = f+> extract =>= f = f+> (f =>= g) =>= h = f =>= (g =>= h)++II. Alternately, you may choose to provide definitions for 'fmap',+'extract', and 'duplicate' satisfying these laws:++> extract . duplicate = id+> fmap extract . duplicate = id+> duplicate . duplicate = fmap duplicate . duplicate++In this case you may not rely on the ability to define 'fmap' in +terms of 'liftW'.++You may of course, choose to define both 'duplicate' /and/ 'extend'. +In that case you must also satisfy these laws:++> extend f = fmap f . duplicate+> duplicate = extend id+> fmap f = extend (f . extract)++These are the default definitions of 'extend' and'duplicate' and +the definition of 'liftW' respectively.++-}
comonad.cabal view
@@ -1,6 +1,6 @@ name: comonad category: Control, Comonads-version: 0.6.0+version: 0.6.1 license: BSD3 cabal-version: >= 1.2 license-file: LICENSE