category-extras 0.44.2 → 0.44.4
raw patch · 62 files changed
+559/−471 lines, 62 filesdep ~base
Dependency ranges changed: base
Files
- LICENSE +23/−22
- category-extras.cabal +37/−40
- src/Control/Applicative/Indexed.hs +0/−29
- src/Control/Applicative/Parameterized.hs +2/−5
- src/Control/Arrow/BiKleisli.hs +4/−3
- src/Control/Arrow/CoKleisli.hs +4/−2
- src/Control/Bifunctor/Associative.hs +1/−1
- src/Control/Bifunctor/Biff.hs +30/−2
- src/Control/Bifunctor/Constant.hs +9/−9
- src/Control/Bifunctor/Fix.hs +24/−2
- src/Control/Bifunctor/Pointed.hs +32/−0
- src/Control/Comonad.hs +6/−3
- src/Control/Comonad/Cofree.hs +1/−1
- src/Control/Comonad/Context.hs +5/−3
- src/Control/Comonad/Fix.hs +26/−0
- src/Control/Comonad/HigherOrder.hs +8/−3
- src/Control/Comonad/Indexed.hs +3/−7
- src/Control/Comonad/Parameterized.hs +5/−26
- src/Control/Comonad/Pointer.hs +1/−4
- src/Control/Comonad/Reader.hs +3/−4
- src/Control/Functor/Adjunction.hs +2/−5
- src/Control/Functor/Adjunction/HigherOrder.hs +29/−0
- src/Control/Functor/Bifunctor.hs +2/−2
- src/Control/Functor/Composition.hs +13/−9
- src/Control/Functor/Composition/Class.hs +0/−20
- src/Control/Functor/Constant.hs +4/−4
- src/Control/Functor/Contravariant.hs +1/−1
- src/Control/Functor/Exponential.hs +1/−1
- src/Control/Functor/Extras.hs +1/−1
- src/Control/Functor/HigherOrder.hs +35/−1
- src/Control/Functor/HigherOrder/Composition.hs +48/−0
- src/Control/Functor/Indexed.hs +15/−13
- src/Control/Functor/KanExtension.hs +9/−4
- src/Control/Functor/Pointed.hs +1/−3
- src/Control/Functor/Pointed/Composition.hs +2/−7
- src/Control/Functor/Pointed/Indexed.hs +0/−39
- src/Control/Functor/Pointed/Parameterized.hs +0/−27
- src/Control/Functor/Representable.hs +1/−1
- src/Control/Functor/Strong.hs +2/−2
- src/Control/Functor/Zap.hs +2/−6
- src/Control/Functor/Zip.hs +4/−8
- src/Control/Monad/Either.hs +36/−6
- src/Control/Monad/Free.hs +4/−3
- src/Control/Monad/HigherOrder.hs +16/−6
- src/Control/Monad/Hyper.hs +14/−5
- src/Control/Monad/Indexed.hs +8/−11
- src/Control/Monad/Indexed/Cont.hs +3/−3
- src/Control/Monad/Indexed/State.hs +57/−7
- src/Control/Monad/Parameterized.hs +13/−34
- src/Control/Monad/Parameterized/Class.hs +0/−57
- src/Control/Morphism/Ana.hs +1/−2
- src/Control/Morphism/Apo.hs +1/−1
- src/Control/Morphism/Cata.hs +1/−1
- src/Control/Morphism/Chrono.hs +1/−2
- src/Control/Morphism/Dyna.hs +1/−3
- src/Control/Morphism/Futu.hs +1/−1
- src/Control/Morphism/Histo.hs +1/−1
- src/Control/Morphism/Hylo.hs +1/−2
- src/Control/Morphism/Meta.hs +1/−1
- src/Control/Morphism/Para.hs +1/−2
- src/Control/Morphism/Zygo.hs +1/−2
- src/Data/Void.hs +1/−1
LICENSE view
@@ -1,27 +1,28 @@-Copyright (c) 2008, Edward Kmett-Copyright (c) 2007, Iavor Diatchki-Copyright (c) 2004-2008, Dave Menendez All rights reserved. -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met:+Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met: - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer.- * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution.- * Neither the name of Edward Kmett nor the names of its other contributors - may be used to endorse or promote products derived from this software - without specific prior written permission.+1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, -INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +2. Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.++3. Neither the name of the author nor the names of his contributors+ may be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
category-extras.cabal view
@@ -1,39 +1,37 @@-name: category-extras-category: Control, Monads, Comonads-version: 0.44.2-license: BSD3-license-file: LICENSE-build-depends: base -any, mtl -any, array -any-author: Edward A. Kmett, Dave Menendez-maintainer: ekmett@gmail.com-stability: experimental-homepage: http://comonad.com/reader/-synopsis: Various modules and constructs inspired by category theory.-build-type: Simple-copyright: Copyright (C) 2008 Edward A. Kmett- Copyright (C) 2004--2008 Dave Menendez- Copyright (C) 2007 Iavor Diatchki-description: A vastly expanded collection of modules implementing various - ideas from category theory. Notable bits include: comonads, - adjunctions, functor fixedpoints and various recursion - operaters ala /Functional Programming with Bananas, Lenses, - Envelopes and Barbed Wire/. --extensions: - CPP, - EmptyDataDecls, - FlexibleContexts,- FlexibleInstances,- FunctionalDependencies, - MultiParamTypeClasses, - TypeOperators,- UndecidableInstances,- ExistentialQuantification,- Rank2Types+name: category-extras+category: Control, Monads, Comonads+version: 0.44.4+license: BSD3+license-file: LICENSE+build-depends: base > 3, mtl, array+author: Edward A. Kmett, Dave Menendez+maintainer: Edward A. Kmett <ekmett@gmail.com>+stability: experimental+homepage: http://comonad.com/reader/+synopsis: Various modules and constructs inspired by category theory+build-type: Simple+copyright: Copyright (C) 2008 Edward A. Kmett+ Copyright (C) 2004--2008 Dave Menendez+ Copyright (C) 2007 Iavor Diatchki+description: A vastly expanded collection of modules implementing various+ ideas from category theory. Notable bits include: comonads,+ adjunctions, functor fixedpoints and various recursion+ operaters ala /Functional Programming with Bananas, Lenses,+ Envelopes and Barbed Wire/. +extensions:+ CPP,+ EmptyDataDecls,+ FlexibleContexts,+ FlexibleInstances,+ FunctionalDependencies,+ MultiParamTypeClasses,+ TypeOperators,+ UndecidableInstances,+ ExistentialQuantification,+ Rank2Types exposed-modules:- Control.Applicative.Indexed, Control.Applicative.Parameterized, Control.Arrow.BiKleisli, Control.Arrow.CoKleisli,@@ -46,11 +44,12 @@ Control.Bifunctor.Functor, Control.Bifunctor.Fix, Control.Bifunctor.Monoidal,+ Control.Bifunctor.Pointed, Control.Bifunctor.Swap, Control.Comonad, Control.Comonad.Cofree, Control.Comonad.Context,--- Control.Comonad.Identity,+ Control.Comonad.Fix, Control.Comonad.Indexed, Control.Comonad.HigherOrder, Control.Comonad.Parameterized,@@ -58,10 +57,10 @@ Control.Comonad.Reader, Control.Comonad.Supply Control.Functor.Adjunction,+ Control.Functor.Adjunction.HigherOrder, Control.Functor.Algebra, Control.Functor.Bifunctor, Control.Functor.Composition- Control.Functor.Composition.Class Control.Functor.Contravariant, Control.Functor.Constant, Control.Functor.Extras,@@ -69,13 +68,12 @@ Control.Functor.Fix, Control.Functor.Full, Control.Functor.HigherOrder,+ Control.Functor.HigherOrder.Composition, Control.Functor.Indexed, Control.Functor.KanExtension, Control.Functor.Strong, Control.Functor.Pointed, Control.Functor.Pointed.Composition,- Control.Functor.Pointed.Indexed,- Control.Functor.Pointed.Parameterized, Control.Functor.Representable, Control.Functor.Zip, Control.Functor.Zap,@@ -85,7 +83,6 @@ Control.Monad.Indexed.State, Control.Monad.Indexed.Cont, Control.Monad.Parameterized,- Control.Monad.Parameterized.Class, Control.Monad.Hyper, Control.Monad.Either, Control.Morphism.Hylo,@@ -101,5 +98,5 @@ Control.Morphism.Histo, Data.Void -ghc-options: -O2 -funbox-strict-fields -hs-source-dirs: src+ghc-options: -Wall -funbox-strict-fields -O2+hs-source-dirs: src
− src/Control/Applicative/Indexed.hs
@@ -1,29 +0,0 @@--------------------------------------------------------------------------------- |--- Module : Control.Applicative.Indexed--- Copyright : (C) 2008 Edward Kmett--- License : BSD-style (see the file LICENSE)------ Maintainer : Edward Kmett <ekmett@gmail.com>--- Stability : experimental--- Portability : non-portable (rank-2 polymorphism)---------------------------------------------------------------------------------module Control.Applicative.Indexed - ( module Control.Applicative- , module Control.Functor.Pointed.Indexed- , IxApplicative(..)- ) where--import Control.Applicative-import Control.Functor.Pointed.Indexed--class IxPointed m => IxApplicative m where- iap :: m i j (a -> b) -> m j k a -> m i k b--instance (Pointed m, Applicative m) => IxApplicative (LiftIx m) where- iap f m = LiftIx (lowerIx f <*> lowerIx m)--instance IxApplicative m => Applicative (LowerIx m i) where- pure = LowerIx . ireturn- f <*> m = LowerIx (liftIx f `iap` liftIx m)
src/Control/Applicative/Parameterized.hs view
@@ -12,13 +12,10 @@ ---------------------------------------------------------------------------- module Control.Applicative.Parameterized ( PApplicative(..)- , module Control.Functor.Pointed.Parameterized+ , PPointed(..) ) where -import Control.Arrow ((|||), (+++))-import Control.Monad-import Control.Monad.Parameterized.Class-import Control.Functor.Pointed.Parameterized +import Control.Bifunctor.Pointed class PPointed f => PApplicative f where pap :: f (a -> b) c -> f a c -> f b c
src/Control/Arrow/BiKleisli.hs view
@@ -1,3 +1,4 @@+{-# OPTIONS_GHC -cpp #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Arrow.BiKleisli@@ -14,7 +15,7 @@ ( BiKleisli(..) ) where -#if __GLASGOW_HASKELL__ >= 609 +#if __GLASGOW_HASKELL__ >= 609 import Prelude hiding (id,(.)) import Control.Category #endif@@ -23,7 +24,7 @@ import Control.Arrow import Control.Functor.Extras -newtype BiKleisli w m a b = BiKleisli { runBiKleisli :: w a -> m b } +newtype BiKleisli w m a b = BiKleisli { runBiKleisli :: w a -> m b } instance Monad m => Functor (BiKleisli w m a) where fmap f (BiKleisli g) = BiKleisli (liftM f . g)@@ -35,7 +36,7 @@ return (u, extract (fmap snd x)) #if __GLASGOW_HASKELL__ < 609 BiKleisli g >>> BiKleisli f = BiKleisli ((>>= f) . dist . extend g)-#else +#else instance (Comonad w, Monad m, Distributes w m) => Category (BiKleisli w m) where BiKleisli f . BiKleisli g = BiKleisli ((>>=f) . dist . extend g) id = BiKleisli (return . extract)
src/Control/Arrow/CoKleisli.hs view
@@ -1,3 +1,5 @@+{-# OPTIONS_GHC -cpp #-}+ ------------------------------------------------------------------------------------------- -- | -- Module : Control.Arrow.CoKleisli@@ -13,14 +15,14 @@ ( CoKleisli(..) ) where -#if __GLASGOW_HASKELL__ >= 609 +#if __GLASGOW_HASKELL__ >= 609 import Prelude hiding (id,(.)) import Control.Category #endif import Control.Comonad import Control.Arrow -newtype CoKleisli w a b = CoKleisli { runCoKleisli :: w a -> b } +newtype CoKleisli w a b = CoKleisli { runCoKleisli :: w a -> b } instance Functor (CoKleisli w a) where fmap f (CoKleisli g) = CoKleisli (f . g)
src/Control/Bifunctor/Associative.hs view
@@ -1,4 +1,4 @@--- {-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}+-- {-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Bifunctor.Associative
src/Control/Bifunctor/Biff.hs view
@@ -11,11 +11,15 @@ ------------------------------------------------------------------------------------------- module Control.Bifunctor.Biff - ( module Control.Bifunctor.Monoidal- , BiffB(..)+ ( BiffB(..) ) where +import Control.Arrow ((|||),(&&&))+import Control.Monad.Identity import Control.Bifunctor.Monoidal+import Control.Functor.Extras+import Control.Monad.Parameterized+import Control.Comonad.Parameterized newtype BiffB p f g a b = BiffB { runBiffB :: p (f a) (g b) } @@ -29,3 +33,27 @@ instance (Functor f, Bifunctor p, Functor g) => Functor (BiffB p f g a) where fmap f = bimap id f++instance FunctorPlus f => PPointed (BiffB (,) Identity f) where+ preturn a = BiffB (Identity a,fzero)++instance Functor f => PPointed (BiffB Either Identity f) where+ preturn = BiffB . Left . Identity++instance Functor f => PCopointed (BiffB (,) Identity f) where+ pextract = runIdentity . fst . runBiffB++instance Functor f => PApplicative (BiffB Either Identity f) where+ pap = papPMonad++instance Functor f => PMonad (BiffB Either Identity f) where+ pbind k = (k . runIdentity ||| BiffB . Right) . runBiffB++instance FunctorPlus f => PApplicative (BiffB (,) Identity f) where+ pap = papPMonad++instance FunctorPlus f => PMonad (BiffB (,) Identity f) where+ pbind k (BiffB ~(Identity a,as)) = BiffB (ib, fplus as bs) where BiffB (ib,bs) = k a++instance Functor f => PComonad (BiffB (,) Identity f) where+ pextend f = BiffB . (Identity . f &&& snd . runBiffB)
src/Control/Bifunctor/Constant.hs view
@@ -26,16 +26,16 @@ newtype ConstB t a b = ConstB { runConstB :: t } instance Bifunctor (ConstB t) where- bimap f g = ConstB . runConstB+ bimap _ _ = ConstB . runConstB instance Functor (ConstB t a) where- fmap f = ConstB . runConstB+ fmap _ = ConstB . runConstB instance ContravariantFunctor (ConstB t a) where- contramap f = ConstB . runConstB+ contramap _ = ConstB . runConstB instance ExpFunctor (ConstB t a) where- xmap f g = ConstB . runConstB+ xmap _ _ = ConstB . runConstB @@ -45,19 +45,19 @@ newtype FstB a b = FstB { runFstB :: a } instance Bifunctor FstB where- bimap f g = FstB . f . runFstB + bimap f _ = FstB . f . runFstB instance Associative FstB where associate = FstB . runFstB . runFstB instance Functor (FstB a) where- fmap f (FstB a) = FstB a+ fmap _ (FstB a) = FstB a instance ContravariantFunctor (FstB a) where- contramap f (FstB a) = FstB a+ contramap _ (FstB a) = FstB a instance ExpFunctor (FstB a) where- xmap f g (FstB a) = FstB a+ xmap _ _ (FstB a) = FstB a @@ -69,7 +69,7 @@ newtype SndB a b = SndB { runSndB :: b } instance Bifunctor SndB where- bimap f g = SndB . g . runSndB + bimap _ g = SndB . g . runSndB instance Functor (SndB a) where fmap = bimap id
src/Control/Bifunctor/Fix.hs view
@@ -11,13 +11,35 @@ ------------------------------------------------------------------------------------------- module Control.Bifunctor.Fix ( FixB(..)- , module Control.Bifunctor+ , paugment+ , pcoaugment ) where -import Control.Bifunctor+import Control.Monad.Parameterized+import Control.Comonad.Parameterized+import Control.Comonad+import Control.Morphism.Hylo newtype FixB s a = InB { outB :: s a (FixB s a) } instance Bifunctor s => Functor (FixB s) where fmap f = InB . bimap f (fmap f) . outB +instance PCopointed f => Copointed (FixB f) where+ extract = pextract . outB++instance PPointed f => Pointed (FixB f) where+ point = InB . preturn++instance PComonad f => Comonad (FixB f) where+ extend k w = pcoaugment (\g -> bihylo InB id g w) k++instance PMonad f => Monad (FixB f) where+ return = InB . preturn+ m >>= k = paugment (\f -> bihylo f id outB m) k++paugment :: PMonad f => (forall c. (f a c -> c) -> c) -> (a -> FixB f b) -> FixB f b+paugment g k = g (InB . pbind (outB . k))++pcoaugment :: PComonad f => ((FixB f a -> f b (FixB f a)) -> FixB f b) -> (FixB f a -> b) -> FixB f b+pcoaugment g k = g (pextend (k . InB) . outB)
+ src/Control/Bifunctor/Pointed.hs view
@@ -0,0 +1,32 @@+-------------------------------------------------------------------------------------------+-- |+-- Module : Control.Bifunctor.Pointed+-- Copyright : 2008 Edward Kmett+-- License : BSD+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (functional-dependencies)+--+-------------------------------------------------------------------------------------------++module Control.Bifunctor.Pointed+ ( PPointed(..)+ , PCopointed(..)+ ) where++import Control.Bifunctor++class Bifunctor f => PPointed f where+ preturn :: a -> f a c ++class Bifunctor f => PCopointed f where+ pextract :: f a c -> a++{-# RULES+"bimap id g . preturn" forall g. bimap id g . preturn = preturn+"pextract . bimap id g" forall g. pextract . bimap id g = pextract+"preturn/pextract" preturn . pextract = id+"pextract/preturn" pextract. preturn = id+ #-}+
src/Control/Comonad.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Comonad@@ -25,9 +25,8 @@ , sequenceW ) where -import Control.Monad+import Control.Monad.Identity import Control.Functor.Pointed-import Control.Arrow ((|||), (&&&), (+++), (***)) infixl 1 =>>, .>> @@ -103,3 +102,7 @@ instance Comonad Identity where extend f x = Identity (f x) duplicate = Identity++instance Comonad ((,)e) where+ duplicate ~(e,a) = (e,(e,a))+
src/Control/Comonad/Cofree.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Comonad.Cofree
src/Control/Comonad/Context.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Comonad.Context@@ -21,7 +21,7 @@ , ContextT(..) ) where -import Control.Arrow ((&&&), first)+import Control.Bifunctor (first) import Control.Comonad class Comonad w => ComonadContext s w | w -> s where@@ -36,11 +36,13 @@ data Context s a = Context (s -> a) s ++runContext :: (Context s s -> Context s b) -> s -> (b, s) runContext f s = (a b, b) where Context a b = f (Context id s) instance ComonadContext s (Context s) where- getC (Context f s) = s+ getC (Context _ s) = s modifyC m (Context f c) = f (m c) instance Functor (Context s) where
+ src/Control/Comonad/Fix.hs view
@@ -0,0 +1,26 @@+-------------------------------------------------------------------------------------------+-- |+-- Module : Control.Comonad.Fix+-- Copyright : 2008 Edward Kmett+-- License : BSD+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : portable+--+-------------------------------------------------------------------------------------------+module Control.Comonad.Fix + ( ComonadFix(..)+ ) where++import Control.Comonad+import Control.Monad.Identity++class Comonad w => ComonadFix w where+ cofix :: w (w a -> a) -> a++instance ComonadFix Identity where+ cofix (Identity f) = fix (f . Identity)++instance ComonadFix ((,)e) where+ cofix ~(e,f) = let x = f (e,x) in x
src/Control/Comonad/HigherOrder.hs view
@@ -11,13 +11,18 @@ -- extending Neil Ghani and Patrician Johann's HFunctor to higher order comonads ---------------------------------------------------------------------------- module Control.Comonad.HigherOrder - ( module Control.Functor.HigherOrder+ ( HFunctor(..)+ , HCopointed(..) , HComonad(..)+ , hduplicate ) where import Control.Functor.Extras (Natural) import Control.Functor.HigherOrder -class HFunctor w => HComonad w where- hextract :: Functor f => Natural (w f) f+class HCopointed w => HComonad w where hextend :: (Functor f, Functor g) => Natural (w f) g -> Natural (w f) (w g)+++hduplicate :: (HComonad w, Functor (w g), Functor g) => w g a -> w (w g) a+hduplicate = hextend id
src/Control/Comonad/Indexed.hs view
@@ -10,15 +10,13 @@ -- ---------------------------------------------------------------------------- module Control.Comonad.Indexed - ( module Control.Comonad- , Control.Functor.Pointed.Indexed.IxPointed(..)- , Control.Functor.Pointed.Indexed.IxCopointed(..)+ ( IxFunctor(..)+ , IxCopointed(..) , IxComonad(..) , iduplicate ) where -import Control.Comonad-import Control.Functor.Pointed.Indexed+import Control.Functor.Indexed class IxCopointed w => IxComonad w where iextend :: (w j k a -> b) -> w i k a -> w i j b@@ -26,5 +24,3 @@ iduplicate :: IxComonad w => w i k a -> w i j (w j k a) iduplicate = iextend id -instance Comonad w => IxComonad (LiftIx w) where- iextend f = LiftIx . extend (f . LiftIx) . lowerIx
src/Control/Comonad/Parameterized.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Comonad.Parameterized@@ -11,19 +11,13 @@ -- ---------------------------------------------------------------------------- module Control.Comonad.Parameterized - ( module Control.Bifunctor.Biff- , module Control.Functor.Pointed.Parameterized- , module Control.Comonad+ ( Bifunctor(..)+ , PCopointed(..) , PComonad(..)- , pcoaugment ) where -import Control.Arrow ((&&&))-import Control.Comonad-import Control.Bifunctor.Fix-import Control.Bifunctor.Biff-import Control.Functor.Pointed.Parameterized-import Control.Morphism.Ana+import Control.Bifunctor+import Control.Bifunctor.Pointed class PCopointed f => PComonad f where pextend :: (f b c -> a) -> f b c -> f a c@@ -41,22 +35,7 @@ {-# RULES "pextend pextract" pextend pextract = id "pextract . pextend g" forall g. pextract . pextend g = g-"pextract . bimap id g" forall g. pextract . bimap id g = pextract "bimap _ _ . pextract" forall j g. bimap id g . pextend (j . bimap id g) = pextend j . bimap id g #-} -pcoaugment :: PComonad f => ((FixB f a -> f b (FixB f a)) -> FixB f b) -> (FixB f a -> b) -> FixB f b-pcoaugment g k = g (pextend (k . InB) . outB)--instance PCopointed f => Copointed (FixB f) where- extract = pextract . outB -instance PComonad f => Comonad (FixB f) where- extend k w = pcoaugment (flip biana w) k--instance Functor f => PCopointed (BiffB (,) Identity f) where- pextract = runIdentity . fst . runBiffB- -instance Functor f => PComonad (BiffB (,) Identity f) where- pextend f = BiffB . (Identity . f &&& snd . runBiffB)-
src/Control/Comonad/Pointer.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Comonad.Pointer@@ -18,10 +18,7 @@ ) where import Control.Functor.Extras-import Control.Arrow ((&&&), first) import Data.Array-import Data.Foldable-import Control.Monad import Control.Comonad data Pointer i a = Pointer { index :: i, array :: Array i a } deriving (Show,Read)
src/Control/Comonad/Reader.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Comonad.Reader@@ -28,6 +28,8 @@ askC :: w a -> r data ReaderC r a = ReaderC r a ++runReaderC :: ReaderC r a -> (r, a) runReaderC (ReaderC r a) = (r,a) instance ComonadReader r (ReaderC r) where@@ -63,9 +65,6 @@ instance Functor f => Bifunctor (ReaderCT f) where bimap f g = ReaderCT . fmap (bimap f g) . runReaderCT --instance Comonad ((,)e) where- duplicate ~(e,a) = (e,(e,a)) instance ComonadReader e ((,)e) where askC = fst
src/Control/Functor/Adjunction.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}+{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Adjunction@@ -15,7 +15,6 @@ import Control.Comonad import Control.Functor.Composition-import Control.Functor.Composition.Class import Control.Functor.Exponential import Control.Functor.Full import Control.Functor.Pointed@@ -42,9 +41,7 @@ rightAdjunct f = counit . fmap f ----- adjunction-oriented composition+-- | Adjunction-oriented composition, yields monads and comonads from adjunctions newtype ACompF f g a = ACompF (CompF f g a) deriving (Functor, ExpFunctor, Full, Composition) instance Adjunction f g => Pointed (ACompF g f) where
+ src/Control/Functor/Adjunction/HigherOrder.hs view
@@ -0,0 +1,29 @@+-----------------------------------------------------------------------------+-- |+-- Module : Control.Functor.Adjunction.HigherOrder+-- Copyright : (C) 2008 Edward Kmett+-- License : BSD-style (see the file LICENSE)+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (rank-2 polymorphism)+--+-- Higher-Order Adjunctions+----------------------------------------------------------------------------+module Control.Functor.Adjunction.HigherOrder + ( HAdjunction(..)+ ) where++import Control.Functor.HigherOrder+import Control.Functor.Extras++class (HFunctor f, HFunctor g) => HAdjunction f g where+ hunit :: Natural a (g (f a))+ hcounit :: Natural (f (g b)) b+ hleftAdjunct :: Natural (f a) b -> Natural a (g b)+ hrightAdjunct :: Natural a (g b) -> Natural (f a) b++ hunit = hleftAdjunct id+ hcounit = hrightAdjunct id+ hleftAdjunct f = hfmap f . hunit+ hrightAdjunct f = hcounit . hfmap f
src/Control/Functor/Bifunctor.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}+{-# OPTIONS_GHC -cpp -fglasgow-exts -fallow-undecidable-instances #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Bifunctor@@ -20,7 +20,7 @@ import Control.Functor.Exponential import Control.Functor.Full import Control.Functor.Pointed-import Control.Arrow ((***),(&&&),(|||),(+++))+import Control.Arrow ((&&&),(|||)) -- * Bifunctor functor transformer
src/Control/Functor/Composition.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -cpp -fglasgow-exts #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Composition@@ -14,24 +14,26 @@ module Control.Functor.Composition ( CompF(..)- , module Control.Functor.Composition.Class- , module Control.Functor.Exponential- , module Control.Functor.Full+ , Composition(..)+ , associateComp+ , coassociateComp+ , (:.:) ) where -import Control.Functor.Composition.Class import Control.Functor.Exponential import Control.Functor.Full +class Composition c where+ decompose :: c f g x -> f (g x)+ compose :: f (g x) -> c f g x+ newtype CompF f g a = CompF { runCompF :: f (g a) } instance Composition CompF where compose = CompF decompose = runCompF --- #ifndef __HADDOCK__ type (f :.: g) a = CompF f g a--- #endif -- common functor composition traits instance (Functor f, Functor g) => Functor (CompF f g) where@@ -43,8 +45,10 @@ instance (Full f, Full g) => Full (CompF f g) where premap f = premap . premap $ decompose . f . compose -associateComp :: (Functor f, Composition c) => (c (c f g) h) a -> (c f (c g h)) a+associateComp :: (Functor f, Composition c) => c (c f g) h a -> c f (c g h) a associateComp = compose . fmap compose . decompose . decompose -coassociateComp :: (Functor f, Composition c) => (c f (c g h)) a -> (c (c f g) h) a+coassociateComp :: (Functor f, Composition c) => c f (c g h) a -> c (c f g) h a coassociateComp = compose . compose . fmap decompose . decompose++
− src/Control/Functor/Composition/Class.hs
@@ -1,20 +0,0 @@-{-# OPTIONS -fglasgow-exts #-}----------------------------------------------------------------------------------------------- |--- Module : Control.Functor.Composition.Class--- Copyright : 2008 Edward Kmett--- License : BSD------ Maintainer : Edward Kmett <ekmett@gmail.com>--- Stability : experimental--- Portability : non-portable (class-associated types)-------------------------------------------------------------------------------------------------module Control.Functor.Composition.Class where--class Composition c where- decompose :: c f g x -> f (g x)- compose :: f (g x) -> c f g x--
src/Control/Functor/Constant.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}+{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Constant@@ -22,12 +22,12 @@ newtype ConstantF a b = ConstantF a instance Functor (ConstantF a) where- fmap f (ConstantF a) = ConstantF a+ fmap _ (ConstantF a) = ConstantF a instance ContravariantFunctor (ConstantF a) where- contramap f (ConstantF a) = ConstantF a+ contramap _ (ConstantF a) = ConstantF a instance ExpFunctor (ConstantF a) where- xmap f g (ConstantF a) = ConstantF a+ xmap _ _ (ConstantF a) = ConstantF a type VoidF a = ConstantF Void a
src/Control/Functor/Contravariant.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Contravariant
src/Control/Functor/Exponential.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Exponential
src/Control/Functor/Extras.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Functor.Extras
src/Control/Functor/HigherOrder.hs view
@@ -1,3 +1,4 @@+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Functor.HigherOrder@@ -11,8 +12,17 @@ -- Neil Ghani and Particia Johann''s higher order functors from -- <http://crab.rutgers.edu/~pjohann/tlca07-rev.pdf> -----------------------------------------------------------------------------module Control.Functor.HigherOrder where+module Control.Functor.HigherOrder + ( HFunctor(..)+ , HPointed(..)+ , HCopointed(..)+ , AlgH+ , CoAlgH+ , FixH(..)+ , LowerH(..)+ ) where +import Control.Functor.Pointed import Control.Functor.Extras type AlgH f g = Natural (f g) g@@ -23,3 +33,27 @@ hfmap :: Natural g h -> Natural (f g) (f h) newtype FixH f a = InH { outH :: f (FixH f) a }++class HFunctor m => HPointed m where+ hreturn :: Functor f => Natural f (m f)++class HFunctor w => HCopointed w where+ hextract :: Functor f => Natural (w f) f++newtype LowerH + (h :: (* -> *) -> * -> *)+ (f :: * -> *)+ (a :: *) = LowerH { liftH :: h f a }++instance (HFunctor h, Functor f) => Functor (LowerH h f) where+ fmap f = LowerH . ffmap f . liftH ++instance (HPointed h, Pointed f) => Pointed (LowerH h f) where+ point = LowerH . hreturn . point++instance (HCopointed h, Copointed f) => Copointed (LowerH h f) where+ extract = extract . hextract . liftH++{-# RULES+"hextract/hreturn" hextract . hreturn = id+ #-}
+ src/Control/Functor/HigherOrder/Composition.hs view
@@ -0,0 +1,48 @@+{-# OPTIONS_GHC -cpp -fglasgow-exts #-}+-------------------------------------------------------------------------------------------+-- |+-- Module : Control.Functor.HigherOrder.Composition+-- Copyright : 2008 Edward Kmett+-- License : BSD+--+-- Maintainer : Edward Kmett <ekmett@gmail.com>+-- Stability : experimental+-- Portability : non-portable (kind annotations, rank-2 types)+--+-- Composition of higher order functors+-------------------------------------------------------------------------------------------++module Control.Functor.HigherOrder.Composition+ ( CompH(..)+ , HComposition(..)+ , hassociateComp+ , hcoassociateComp+ ) where++import Control.Functor.HigherOrder++class HComposition + (c :: ((* -> *) -> * -> *) -> + ((* -> *) -> * -> *) -> + ((* -> *) -> * -> *)) where+ hcompose :: f (g x) a -> c f g x a+ hdecompose :: c f g x a -> f (g x) a++newtype CompH + (f :: ((* -> *) -> * -> *))+ (g :: ((* -> *) -> * -> *)) + (a :: (* -> *)) (b :: *) = CompH { runCompH :: f (g a) b }++instance HComposition CompH where+ hcompose = CompH+ hdecompose = runCompH++instance (HFunctor f, HFunctor g) => HFunctor (CompH f g) where+ hfmap f = hcompose . hfmap (hfmap f) . hdecompose+ ffmap f = hcompose . hfmap liftH . ffmap f . hfmap LowerH . hdecompose++hassociateComp :: (HFunctor f, HComposition c) => c (c f g) h a b -> c f (c g h) a b+hassociateComp = hcompose . hfmap hcompose . hdecompose . hdecompose++hcoassociateComp :: (HFunctor f, HComposition c) => c f (c g h) a b -> c (c f g) h a b+hcoassociateComp = hcompose . hcompose . hfmap hdecompose . hdecompose
src/Control/Functor/Indexed.hs view
@@ -9,23 +9,25 @@ -- Portability : portable -- -----------------------------------------------------------------------------module Control.Functor.Indexed where--import Control.Comonad-import Control.Arrow-import Control.Functor.Extras-import Control.Functor.HigherOrder-import Control.Monad+module Control.Functor.Indexed + ( IxFunctor(..)+ , IxCopointed(..)+ , IxPointed(..)+ , IxApplicative(..)+ ) where class IxFunctor f where imap :: (a -> b) -> f j k a -> f j k b -newtype LiftIx m i j a = LiftIx { lowerIx :: m a }+class IxPointed m => IxApplicative m where+ iap :: m i j (a -> b) -> m j k a -> m i k b -instance Functor f => IxFunctor (LiftIx f) where- imap f = LiftIx . fmap f . lowerIx+class IxFunctor m => IxPointed m where+ ireturn :: a -> m i i a -newtype LowerIx m i a = LowerIx { liftIx :: m i i a } +class IxFunctor w => IxCopointed w where+ iextract :: w i i a -> a -instance IxFunctor f => Functor (LowerIx f i) where- fmap f = LowerIx . imap f . liftIx+{-# RULES+"iextract/ireturn" iextract . ireturn = id+ #-}
src/Control/Functor/KanExtension.hs view
@@ -9,12 +9,17 @@ -- Portability : non-portable (rank-2 polymorphism) -- -----------------------------------------------------------------------------module Control.Functor.KanExtension where+module Control.Functor.KanExtension + ( Ran(..)+ , toRan, fromRan+ , Lan(..)+ , toLan, fromLan+ ) where -import Control.Functor.Composition.Class+import Control.Functor.Composition import Control.Functor.Extras --- Right Kan Extension+-- | Right Kan Extension newtype Ran g h a = Ran { runRan :: forall b. (a -> g b) -> h b } toRan :: (Composition c, Functor k) => Natural (c k g) h -> Natural k (Ran g h)@@ -23,7 +28,7 @@ fromRan :: Composition c => Natural k (Ran g h) -> Natural (c k g) h fromRan s = flip runRan id . s . decompose --- Left Kan Extension+-- | Left Kan Extension data Lan g h a = forall b. Lan (g b -> a) (h b) toLan :: (Composition c, Functor f) => Natural h (c f g) -> Natural (Lan g h) f
src/Control/Functor/Pointed.hs view
@@ -11,8 +11,7 @@ ------------------------------------------------------------------------------------------- module Control.Functor.Pointed - ( module Control.Monad.Identity- , Pointed(..)+ ( Pointed(..) , Copointed(..) ) where @@ -27,7 +26,6 @@ {-# RULES "extract/point" extract . point = id-"point/extract" point . extract = id #-} instance Pointed Identity where
src/Control/Functor/Pointed/Composition.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Pointed.Composition@@ -13,18 +13,13 @@ ------------------------------------------------------------------------------------------- module Control.Functor.Pointed.Composition - ( Control.Functor.Pointed.Pointed(..)- , Control.Functor.Pointed.Copointed(..)- , module Control.Functor.Extras- , module Control.Functor.Composition- , PointedCompF(..)+ ( PointedCompF(..) , PostCompF(..) , PreCompF(..) , DistCompF(..) ) where import Control.Functor.Extras-import Control.Functor.Pointed import Control.Functor.Composition import Control.Comonad import Control.Monad
− src/Control/Functor/Pointed/Indexed.hs
@@ -1,39 +0,0 @@----------------------------------------------------------------------------------------------- |--- Module : Control.Functor.Pointed.Indexed--- Copyright : 2008 Edward Kmett--- License : BSD3------ Maintainer : Edward Kmett <ekmett@gmail.com>--- Stability : experimental--- Portability : portable-------------------------------------------------------------------------------------------------module Control.Functor.Pointed.Indexed - ( IxPointed(..)- , IxCopointed(..)- , module Control.Functor.Indexed- , module Control.Functor.Pointed- )where--import Control.Functor.Pointed-import Control.Functor.Indexed--class IxFunctor m => IxPointed m where- ireturn :: a -> m i i a--class IxFunctor w => IxCopointed w where- iextract :: w i i a -> a--instance Pointed m => IxPointed (LiftIx m) where- ireturn = LiftIx . point--instance Copointed m => IxCopointed (LiftIx m) where- iextract = extract . lowerIx--{-# RULES-"ireturn/iextract" ireturn . iextract = id-"iextract/ireturn" iextract . ireturn = id- #-}-
− src/Control/Functor/Pointed/Parameterized.hs
@@ -1,27 +0,0 @@----------------------------------------------------------------------------------------------- |--- Module : Control.Functor.Pointed.Parameterized--- Copyright : 2008 Edward Kmett--- License : BSD------ Maintainer : Edward Kmett <ekmett@gmail.com>--- Stability : experimental--- Portability : non-portable (functional-dependencies)-------------------------------------------------------------------------------------------------module Control.Functor.Pointed.Parameterized where--import Control.Bifunctor--class Bifunctor f => PPointed f where- preturn :: a -> f a c --class Bifunctor f => PCopointed f where- pextract :: f a c -> a--{-# RULES-"preturn/pextract" preturn . pextract = id-"pextract/preturn" pextract. preturn = id- #-}-
src/Control/Functor/Representable.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Representable
src/Control/Functor/Strong.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}+{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Strong@@ -15,7 +15,7 @@ import Prelude hiding (sequence) import Data.Traversable-import Control.Monad.Either+import Control.Monad.Either () strength :: Functor f => f a -> b -> f (a,b) strength fa b = fmap (\a -> (a,b)) fa
src/Control/Functor/Zap.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts -fallow-undecidable-instances #-}+{-# OPTIONS_GHC -fglasgow-exts -fallow-undecidable-instances #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Functor.Zap@@ -14,13 +14,9 @@ module Control.Functor.Zap where -import Control.Bifunctor-import Control.Bifunctor.Composition import Control.Comonad.Cofree-import Control.Monad.Either-import Control.Monad.Free+import Control.Monad.Either () import Control.Monad.Identity-import Data.Traversable {- | Minimum definition: zapWith -}
src/Control/Functor/Zip.hs view
@@ -21,11 +21,7 @@ ) where import Control.Arrow ((&&&),(|||))-import Control.Bifunctor-import Control.Bifunctor.Composition import Control.Bifunctor.Functor-import Control.Bifunctor.Biff-import Control.Bifunctor.Fix import Control.Comonad.Cofree import Control.Monad.Free import Control.Monad.Identity@@ -74,7 +70,7 @@ instance Zip Maybe where fzipWith f (Just a) (Just b) = Just (f a b)- fzipWith f _ _ = Nothing+ fzipWith _ _ _ = Nothing instance Monoid a => Zip ((,)a) where fzipWith f (a, c) (b, d) = (mappend a b, f c d)@@ -96,9 +92,9 @@ fzipWith f as bs = InB $ bizipWith f (fzipWith f) (outB as) (outB bs) instance Monoid a => Zip (Either a) where- fzipWith f (Left a) (Left b) = Left (mappend a b)- fzipWith f (Right a) (Left b) = Left b- fzipWith f (Left a) (Right b) = Left a+ fzipWith _ (Left a) (Left b) = Left (mappend a b)+ fzipWith _ (Right _) (Left b) = Left b+ fzipWith _ (Left a) (Right _) = Left a fzipWith f (Right a) (Right b) = Right (f a b)
src/Control/Monad/Either.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.Either@@ -13,29 +13,59 @@ -- that prevents a natural encoding of Apomorphisms. This module is -- therefore incompatible with Control.Monad.Error -----------------------------------------------------------------------------module Control.Monad.Either where+module Control.Monad.Either + ( Either(..)+ , EitherT(..)+ ) where import Data.Either+import Control.Applicative import Control.Monad+import Control.Monad.Fix+import Control.Functor.Pointed newtype EitherT a m b = EitherT { runEitherT :: m (Either a b) } +{- instance Functor (Either e) where fmap _ (Left a) = Left a fmap f (Right a) = Right (f a) +instance Pointed (Either e) where+ point = Right+-}++instance Applicative (Either e) where+ pure = Right+ (<*>) = ap+ instance Monad (Either e) where return = Right Right m >>= k = k m Left e >>= _ = Left e -instance Functor f => Functor (EitherT b f) where+instance MonadFix (Either e) where+ mfix f = let + a = f $ case a of+ Right r -> r+ _ -> error "empty mfix argument"+ in a++instance Functor f => Functor (EitherT a f) where fmap f = EitherT . fmap (fmap f) . runEitherT -instance Monad m => Monad (EitherT b m) where+instance Pointed f => Pointed (EitherT a f) where+ point = EitherT . point . Right++instance Monad m => Monad (EitherT a m) where return = EitherT . return . return m >>= k = EitherT $ do a <- runEitherT m case a of- Left l -> return (Left l)- Right r -> runEitherT (k r)+ Left l -> return (Left l)+ Right r -> runEitherT (k r)++instance MonadFix m => MonadFix (EitherT a m) where+ mfix f = EitherT $ mfix $ \a -> runEitherT $ f $ case a of+ Right r -> r+ _ -> error "empty mfix argument"
src/Control/Monad/Free.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.Free@@ -21,8 +21,9 @@ , free ) where -import Control.Arrow ((|||), (+++))-import Control.Bifunctor (first)+import Control.Arrow ((|||))+import Control.Bifunctor.Biff+import Control.Bifunctor.Fix import Control.Monad.Parameterized import Control.Monad.Identity
src/Control/Monad/HigherOrder.hs view
@@ -9,18 +9,28 @@ -- Portability : non-portable (rank-2 polymorphism) -- -----------------------------------------------------------------------------module Control.Monad.HigherOrder where+module Control.Monad.HigherOrder + ( HFunctor(..)+ , HPointed(..)+ , HMonad(..)+ , hjoin+ , (>>**=), (=**<<)+ ) where -import Control.Functor.Extras+import Control.Functor.Extras (Natural) import Control.Functor.HigherOrder -class HFunctor m => HMonad m where- hreturn :: Functor f => Natural f (m f)+infixl 1 >>**=+infixr 1 =**<<++class HPointed m => HMonad m where hbind :: (Functor f, Functor g) => Natural f (m g) -> Natural (m f) (m g)- --hbind k = hjoin . hfmap k -hjoin :: (HMonad m, Functor (m g), Functor g) => Natural (m (m g)) (m g)+hjoin :: (HMonad m, Functor (m g), Functor g) => m (m g) a -> m g a hjoin = hbind id (>>**=) :: (HMonad m, Functor f, Functor g) => m f a -> Natural f (m g) -> m g a m >>**= k = hbind k m ++(=**<<) :: (HMonad m, Functor f, Functor g) => Natural f (m g) -> Natural (m f) (m g)+(=**<<) = hbind
src/Control/Monad/Hyper.hs view
@@ -12,11 +12,15 @@ -- <http://crab.rutgers.edu/~pjohann/f14-ghani.pdf> ------------------------------------------------------------------------------------------- -module Control.Monad.Hyper where+module Control.Monad.Hyper + ( ContravariantFunctor(..)+ , Hyper+ , Hyp+ , HyperB(..)+ ) where -import Control.Bifunctor import Control.Bifunctor.Fix-import Control.Monad.Parameterized.Class+import Control.Monad.Parameterized import Control.Functor.Contravariant import Control.Monad.Instances @@ -25,9 +29,14 @@ instance ContravariantFunctor h => Bifunctor (HyperB h) where bimap f g h = HyperB (f . runHyperB h . contramap g) -instance ContravariantFunctor h => PMonad (HyperB h) where+instance ContravariantFunctor h => PPointed (HyperB h) where preturn = HyperB . const- pbind k (HyperB h) = HyperB (k . h >>= runHyperB) -- the bind is in the (->)e monad++instance ContravariantFunctor h => PApplicative (HyperB h) where+ pap = papPMonad++instance ContravariantFunctor h => PMonad (HyperB h) where+ pbind k (HyperB h) = HyperB (k . h >>= runHyperB) -- | A generic recursive hyperfunction-like combinator type Hyper h a = FixB (HyperB h)
src/Control/Monad/Indexed.hs view
@@ -10,15 +10,15 @@ -- ---------------------------------------------------------------------------- module Control.Monad.Indexed - ( module Control.Applicative.Indexed+ ( IxFunctor(..)+ , IxPointed(..)+ , IxApplicative(..) , IxMonad(..)- , ijoin, (>>>=)+ , ijoin, (>>>=), (=<<<) , iapIxMonad ) where -import Control.Arrow-import Control.Applicative.Indexed-import Control.Monad+import Control.Functor.Indexed class IxApplicative m => IxMonad m where ibind :: (a -> m j k b) -> m i j a -> m i k b@@ -26,17 +26,14 @@ ijoin :: IxMonad m => m i j (m j k a) -> m i k a ijoin = ibind id +infixr 1 =<<< infixl 1 >>>= (>>>=) :: IxMonad m => m i j a -> (a -> m j k b) -> m i k b m >>>= k = ibind k m -instance (Pointed m, Applicative m, Monad m) => IxMonad (LiftIx m) where- ibind f m = LiftIx (lowerIx m >>= lowerIx . f)--instance IxMonad m => Monad (LowerIx m i) where- return = LowerIx . ireturn- m >>= f = LowerIx (liftIx m >>>= liftIx . f)+(=<<<) :: IxMonad m => (a -> m j k b) -> m i j a -> m i k b+(=<<<) = ibind iapIxMonad :: IxMonad m => m i j (a -> b) -> m j k a -> m i k b iapIxMonad f x = f >>>= \ f' -> x >>>= \x' -> ireturn (f' x')
src/Control/Monad/Indexed/Cont.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ------------------------------------------------------------------------------------------- -- | -- Module : Control.Monad.Indexed.Cont@@ -7,7 +7,7 @@ -- -- Maintainer : Edward Kmett <ekmett@gmail.com> -- Stability : experimental--- Portability : portable+-- Portability : Rank-2 Types -- ------------------------------------------------------------------------------------------- @@ -18,7 +18,7 @@ class IxMonad m => IxMonadCont m where reset :: m a o o -> m r r a- shift :: ((a -> m i i o) -> m r j j) -> m r o a+ shift :: (forall i. (a -> m i i o) -> m r j j) -> m r o a newtype IxContT m r o a = IxContT { runIxContT :: (a -> m o) -> m r }
src/Control/Monad/Indexed/State.hs view
@@ -11,18 +11,28 @@ ---------------------------------------------------------------------------- module Control.Monad.Indexed.State where -import Control.Comonad-import Control.Arrow-import Control.Functor.Extras-import Control.Functor.HigherOrder-import Control.Functor.Indexed+import Control.Arrow ((***))+import Control.Bifunctor (Bifunctor(bimap), first) import Control.Monad import Control.Monad.Indexed +class IxMonad m => IxMonadState m where+ iget :: m i i i+ iput :: j -> m i j ()++imodify :: IxMonadState m => (i -> j) -> m i j ()+imodify f = iget >>>= iput . f++igets :: IxMonadState m => (i -> a) -> m i i a+igets f = iget >>>= ireturn . f+ newtype IxState i j a = IxState { runIxState :: i -> (a, j) } +instance Functor (IxState i j) where+ fmap = imap+ instance IxFunctor IxState where- imap f (IxState m) = IxState (first f . m)+ imap f m = IxState (first f . runIxState m) instance IxPointed IxState where ireturn = IxState . (,)@@ -31,4 +41,44 @@ iap = iapIxMonad instance IxMonad IxState where- ibind f (IxState m) = IxState $ \s1 -> let (a,s2) = m s1 in runIxState (f a) s2 + ibind f m = IxState $ \s1 -> let (a,s2) = runIxState m s1 in runIxState (f a) s2 ++instance IxMonadState IxState where+ iget = IxState (\x -> (x,x))+ iput x = IxState (\_ -> ((),x))++instance Bifunctor (IxState i) where + bimap f g m = IxState $ (g *** f) . runIxState m++newtype IxStateT m i j a = IxStateT { runIxStateT :: i -> m (a, j) }++instance Monad m => Functor (IxStateT m i j) where+ fmap = imap++instance Monad m => IxFunctor (IxStateT m) where+ imap f m = IxStateT $ \s -> runIxStateT m s >>= \(x,s') -> return (f x, s')++instance Monad m => IxPointed (IxStateT m) where+ ireturn a = IxStateT $ \s -> return (a, s)++instance Monad m => IxApplicative (IxStateT m) where+ iap = iapIxMonad ++instance Monad m => IxMonad (IxStateT m) where+ ibind k m = IxStateT $ \s -> runIxStateT m s >>= \ ~(a, s') -> runIxStateT (k a) s'++instance Monad m => Bifunctor (IxStateT m i) where+ bimap f g m = IxStateT $ liftM (g *** f) . runIxStateT m++instance Monad m => IxMonadState (IxStateT m) where+ iget = IxStateT $ \s -> return (s, s)+ iput s = IxStateT $ \_ -> return ((), s)++{-+instance MonadPlus m => IxMonadPlus (IxStateT m) where+ izero = IxStateT $ \_ -> mzero+ m `iplus` n = IxStateT $ \s -> runIxStateT m s `mplus` runIxStateT n s++instance MonadFix m => IxMonadFix (IxStateT m) where+ ifix f = StateT $ \s -> mfix $ \ ~(a, _) -> runStateT (f a) s+-}
src/Control/Monad/Parameterized.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.Paramterized@@ -11,37 +11,36 @@ -- ---------------------------------------------------------------------------- module Control.Monad.Parameterized - ( FixB(..)- , BiffB(..)+ ( Bifunctor(..) , PPointed(..)+ , PApplicative(..) , PMonad(..) , (>>*=), (=*<<), (>>*)- , paugment+ , papPMonad ) where -import Control.Arrow ((|||), (+++)) import Control.Bifunctor-import Control.Bifunctor.Fix-import Control.Bifunctor.Biff-import Control.Monad.Identity-import Control.Functor.Extras-import Control.Functor.Pointed.Parameterized-import Control.Monad-import Control.Morphism.Cata+import Control.Applicative.Parameterized -class PPointed f => PMonad f where+infixl 1 >>*=, >>*+infixr 1 =*<< ++class PApplicative f => PMonad f where pbind :: (a -> f b c) -> f a c -> f b c pbind f = pjoin . bimap f id pjoin :: f (f a b) b -> f a b pjoin = pbind id +papPMonad :: PMonad f => f (a -> b) c -> f a c -> f b c+papPMonad f x = f >>*= \ f' -> x >>*= \x' -> preturn (f' x')+ (>>*=) :: PMonad f => f a c -> (a -> f b c) -> f b c (>>*=) = flip pbind (=*<<) :: PMonad f => (a -> f b c) -> f a c -> f b c (=*<<) = pbind --- (>>*) :: PMonad f => f a c -> f b c -> f b c +(>>*) :: PMonad f => f a c -> f b c -> f b c m >>* n = m >>*= const n {- Parameterized monad laws (from <http://crab.rutgers.edu/~pjohann/f14-ghani.pdf>)@@ -52,23 +51,3 @@ > pbind (pmap g . j) . pmap g = pmap g . pbind j -} -paugment :: PMonad f => (forall c. (f a c -> c) -> c) -> (a -> FixB f b) -> FixB f b-paugment g k = g (InB . pbind (outB . k))--instance PMonad f => Monad (FixB f) where- return = InB . preturn- m >>= k = paugment (flip bicata m) k--instance Functor f => PPointed (BiffB Either Identity f) where- preturn = BiffB . Left . Identity---- The Free Monad-instance Functor f => PMonad (BiffB Either Identity f) where- pbind k = (k . runIdentity ||| BiffB . Right) . runBiffB--instance FunctorPlus f => PPointed (BiffB (,) Identity f) where- preturn a = BiffB (Identity a,fzero)---- The 'Cofree' Monad-instance FunctorPlus f => PMonad (BiffB (,) Identity f) where- pbind k (BiffB ~(Identity a,as)) = BiffB (ib, fplus as bs) where BiffB (ib,bs) = k a
− src/Control/Monad/Parameterized/Class.hs
@@ -1,57 +0,0 @@-{-# OPTIONS -fglasgow-exts #-}--------------------------------------------------------------------------------- |--- Module : Control.Monad.Paramterized.Class--- Copyright : (C) 2008 Edward Kmett--- License : BSD-style (see the file LICENSE)------ Maintainer : Edward Kmett <ekmett@gmail.com>--- Stability : experimental--- Portability : portable------ The notation >>*= was selected to indicate the kind of the parameter--- in this case a simple type as opposed to >>*->*= for higher order monads.------------------------------------------------------------------------------module Control.Monad.Parameterized.Class where--import Control.Arrow ((|||), (+++))--- import Control.Functor.Exponential--- import Control.Functor.Contravariant-import Control.Monad-import Control.Bifunctor-import Control.Bifunctor.Fix--{- | Minimum definition:--1. preturn & pbind-2. preturn & pjoin---}- -class Bifunctor f => PMonad f where- preturn :: a -> f a c- pbind :: (a -> f b c) -> f a c -> f b c- pbind f = pjoin . bimap f id- pjoin :: f (f a b) b -> f a b- pjoin = pbind id--(>>*=) :: PMonad f => f a c -> (a -> f b c) -> f b c-(>>*=) = flip pbind--(=*<<) :: PMonad f => (a -> f b c) -> f a c -> f b c-(=*<<) = pbind---- (>>*) :: PMonad f => f a c -> f b c -> f b c -m >>* n = m >>*= const n---- bimapPMonad :: (PMonad f, Functor (f a)) => (a -> c) -> (b -> d) -> f a b -> f c d --- bimapPMonad f g xs = second g xs >>*= preturn . f--{- Parameterized monad laws (from <http://crab.rutgers.edu/~pjohann/f14-ghani.pdf>)-> pbind preturn = id-> pbind g . preturn = g-> pbind (pbind g . j) = pbind g . pbind j-> pmap g . preturn = preturn-> pbind (pmap g . j) . pmap g = pmap g . pbind j --}-
src/Control/Morphism/Ana.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Ana@@ -20,7 +20,6 @@ import Control.Bifunctor.Fix import Control.Comonad () import Control.Monad.Identity-import Control.Comonad.Identity () -- | Anamorphisms are a generalized form of 'unfoldr' ana :: Functor f => CoAlg f a -> a -> Fix f
src/Control/Morphism/Apo.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Apo
src/Control/Morphism/Cata.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Cata
src/Control/Morphism/Chrono.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Chrono@@ -16,7 +16,6 @@ import Control.Comonad.Cofree import Control.Functor.Algebra import Control.Functor.Extras-import Control.Functor.Fix import Control.Monad.Free import Control.Morphism.Hylo import Control.Morphism.Futu
src/Control/Morphism/Dyna.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Dyna@@ -14,8 +14,6 @@ import Control.Functor.Algebra import Control.Functor.Extras-import Control.Functor.Fix-import Control.Comonad import Control.Comonad.Cofree import Control.Morphism.Hylo import Control.Morphism.Histo
src/Control/Morphism/Futu.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Futu
src/Control/Morphism/Histo.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Histo
src/Control/Morphism/Hylo.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Hylo@@ -18,7 +18,6 @@ import Control.Monad import Control.Functor.Algebra import Control.Functor.Extras-import Control.Functor.Fix import Control.Functor.HigherOrder hylo :: Functor f => Alg g b -> Natural f g -> CoAlg f a -> a -> b
src/Control/Morphism/Meta.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Meta
src/Control/Morphism/Para.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Para@@ -12,7 +12,6 @@ ---------------------------------------------------------------------------- module Control.Morphism.Para where -import Control.Comonad import Control.Comonad.Reader import Control.Functor.Algebra import Control.Functor.Extras
src/Control/Morphism/Zygo.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Control.Morphism.Zygo @@ -13,7 +13,6 @@ module Control.Morphism.Zygo where import Control.Arrow ((&&&))-import Control.Comonad import Control.Comonad.Reader import Control.Functor.Algebra import Control.Functor.Extras
src/Data/Void.hs view
@@ -1,4 +1,4 @@-{-# OPTIONS -fglasgow-exts #-}+{-# OPTIONS_GHC -fglasgow-exts #-} ----------------------------------------------------------------------------- -- | -- Module : Data.Void