-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Graph indexed monads. -- -- Graph indexed monads. @package graphted @version 0.3.1.0 -- | description starting at first column module Data.Functor.Graph -- | Graph indexed functor. class GFunctor (f :: p -> * -> *) where type Fmap f (i :: p) :: p type Replace f (i :: p) :: p type EfficientReplace f :: Bool type Fmap f i = i type Replace f i = Fmap f i type EfficientReplace f = False greplace = gmap . const where { type family Fmap f (i :: p) :: p; type family Replace f (i :: p) :: p; type family EfficientReplace f :: Bool; type Fmap f i = i; type Replace f i = Fmap f i; type EfficientReplace f = False; } -- | Map a function over over the functor (fmap). gmap :: GFunctor f => (a -> b) -> f i a -> f (Fmap f i) b -- | Replace all values with a constant (<$). -- -- Default implementation requires the default instance of -- Replace. greplace :: GFunctor f => a -> f i b -> f (Replace f i) a -- | Replace all values with a constant (<$). -- -- Default implementation requires the default instance of -- Replace. greplace :: (GFunctor f, Replace f i ~ Fmap f i) => a -> f i b -> f (Replace f i) a -- | This should only be implemented when the replace operation has a more -- efficient greplace than gmap . const. class GFunctorReplace (f :: p -> * -> *) module Control.Graphted.Class -- | Base class that all Graph-indexed types may implement. class Graphted (f :: p -> * -> *) where type Unit f :: p type Inv f (i :: p) (j :: p) :: Constraint type Combine f (i :: p) (j :: p) :: p type Inv f i j = () where { type family Unit f :: p; type family Inv f (i :: p) (j :: p) :: Constraint; type family Combine f (i :: p) (j :: p) :: p; type Inv f i j = (); } -- | The kind of constraints, like Show a data Constraint :: * module Data.Pointed.Graph -- | Graph indexed pointed functor. class GPointed (f :: p -> * -> *) where type Pure f :: p type PureCxt f (i :: p) :: Constraint type Pure f = Unit f type PureCxt f i = () gpure = gpureAt @(Pure f) where { type family Pure f :: p; type family PureCxt f (i :: p) :: Constraint; type Pure f = Unit f; type PureCxt f i = (); } -- | Return a pointed functor indexed by the Pure type instance -- (pure). -- --
--   >>> :t gpure @_ @(GWrapped Maybe) "Hello, World"
--   :: GWrapped Maybe () [Char]
--   
gpure :: forall a. GPointed f => a -> f (Pure f) a -- | Return a pointed functor indexed by the Pure type instance -- (pure). -- --
--   >>> :t gpure @_ @(GWrapped Maybe) "Hello, World"
--   :: GWrapped Maybe () [Char]
--   
gpure :: (GPointed f, PureCxt f (Pure f)) => a -> f (Pure f) a -- | Return a pointed functor indexed by a type t in the domain of -- p. -- -- Accessible with type applications, e.g.: -- --
--   >>> :t gpure' @_ @(GWrapped Maybe) @Int
--   gpure' @_ @(GWrapped Maybe) @Int :: a -> GWrapped Maybe Int a
--   
gpure' :: forall t a. (GPointed f, PureCxt f t) => a -> f t a -- | Return a pointed functor with a given type in the index. -- -- Accessible with type applications, e.g.: -- --
--   >>> :t gpureAt @Int
--   gpureAt @Int :: (GPointed f, PureCxt f Int) => a -> f Int a
--   
gpureAt :: forall t a f. (GPointed f, PureCxt f t) => a -> f t a module Control.Applicative.Graph class GApplicativeThen useReplace (f :: p -> * -> *) gdefaultThenProxy :: (GApplicativeThen useReplace f, DefaultThenCxt useReplace f i j) => proxy useReplace -> f i a -> f j b -> f (Then f i j) b gdefaultThen :: (GApplicativeThen useReplace f, DefaultThenCxt useReplace f i j) => f i a -> f j b -> f (Then f i j) b -- | Graph indexed applicative functor. class (GFunctor f, GPointed f) => GApplicative (f :: p -> * -> *) where type Apply f (i :: p) (j :: p) :: p type ApplyInv f (i :: p) (j :: p) :: Constraint type LiftA2 f (i :: p) (j :: p) :: p type LiftA2Inv f (i :: p) (j :: p) :: Constraint type ThenUseReplace f :: Bool type Then f (i :: p) (j :: p) :: p type ThenInv f (i :: p) (j :: p) :: Constraint type But f (i :: p) (j :: p) :: p type ButInv f (i :: p) (j :: p) :: Constraint type Apply f i j = Combine f i j type ApplyInv f i j = Inv f i j type LiftA2 f i j = Apply f (Fmap f i) j type LiftA2Inv f i j = ApplyInv f i j type ThenUseReplace f = EfficientReplace f type Then f i j = DefaultThen (ThenUseReplace f) f i j type ThenInv f i j = ApplyInv f i j type But f i j = LiftA2 f i j type ButInv f i j = ApplyInv f i j gliftA2 f x = gap (gmap f x) gthen a b = gdefaultThen @(ThenUseReplace f) a b gbut = gliftA2 const where { type family Apply f (i :: p) (j :: p) :: p; type family ApplyInv f (i :: p) (j :: p) :: Constraint; type family LiftA2 f (i :: p) (j :: p) :: p; type family LiftA2Inv f (i :: p) (j :: p) :: Constraint; type family ThenUseReplace f :: Bool; type family Then f (i :: p) (j :: p) :: p; type family ThenInv f (i :: p) (j :: p) :: Constraint; type family But f (i :: p) (j :: p) :: p; type family ButInv f (i :: p) (j :: p) :: Constraint; type Apply f i j = Combine f i j; type ApplyInv f i j = Inv f i j; type LiftA2 f i j = Apply f (Fmap f i) j; type LiftA2Inv f i j = ApplyInv f i j; type ThenUseReplace f = EfficientReplace f; type Then f i j = DefaultThen (ThenUseReplace f) f i j; type ThenInv f i j = ApplyInv f i j; type But f i j = LiftA2 f i j; type ButInv f i j = ApplyInv f i j; } -- | Sequential application (<*>). gap :: (GApplicative f, ApplyInv f i j) => f i (a -> b) -> f j a -> f (Apply f i j) b -- | Lift a binary function to actions. -- -- Default implementation is defined in terms of Apply and -- Fmap. gliftA2 :: (GApplicative f, LiftA2Inv f i j) => (a -> b -> c) -> f i a -> f j b -> f (LiftA2 f i j) c -- | Lift a binary function to actions. -- -- Default implementation is defined in terms of Apply and -- Fmap. gliftA2 :: (GApplicative f, Apply f (Fmap f i) j ~ LiftA2 f i j, ApplyInv f (Fmap f i) j) => (a -> b -> c) -> f i a -> f j b -> f (LiftA2 f i j) c -- | Sequence actions, discarding the value of the first argument -- (*>). -- -- Default implementation requires the default instance of Then. gthen :: (GApplicative f, ThenInv f i j) => f i a -> f j b -> f (Then f i j) b -- | Sequence actions, discarding the value of the first argument -- (*>). -- -- Default implementation requires the default instance of Then. gthen :: (GApplicative f, GApplicativeThen (ThenUseReplace f) f, DefaultThenCxt (ThenUseReplace f) f i j) => f i a -> f j b -> f (Then f i j) b -- | Sequence actions, discarding values of the second argument -- (<*). -- -- Default implementation requires the default instance of But. gbut :: (GApplicative f, ButInv f i j) => f i a -> f j b -> f (But f i j) a -- | Sequence actions, discarding values of the second argument -- (<*). -- -- Default implementation requires the default instance of But. gbut :: (GApplicative f, LiftA2 f i j ~ But f i j, LiftA2Inv f i j) => f i a -> f j b -> f (But f i j) a instance forall p (f :: p -> GHC.Types.* -> GHC.Types.*). Control.Applicative.Graph.GApplicative f => Control.Applicative.Graph.GApplicativeThen 'GHC.Types.True f instance forall p (f :: p -> GHC.Types.* -> GHC.Types.*). Control.Applicative.Graph.GApplicative f => Control.Applicative.Graph.GApplicativeThen 'GHC.Types.False f module Control.Monad.Graph -- | Graph indexed monad. class GApplicative m => GMonad (m :: p -> * -> *) where type Bind m (i :: p) (j :: p) :: p type BindInv m (i :: p) (j :: p) :: Constraint type Join m (i :: p) (j :: p) :: p type JoinInv m (i :: p) (j :: p) :: Constraint type Bind m i j = Combine m i j type BindInv m i j = Inv m i j type Join m i j = Bind m i j type JoinInv m i j = BindInv m i j gjoin x = x `gbind` id where { type family Bind m (i :: p) (j :: p) :: p; type family BindInv m (i :: p) (j :: p) :: Constraint; type family Join m (i :: p) (j :: p) :: p; type family JoinInv m (i :: p) (j :: p) :: Constraint; type Bind m i j = Combine m i j; type BindInv m i j = Inv m i j; type Join m i j = Bind m i j; type JoinInv m i j = BindInv m i j; } -- | Sequentially compose two actions, with the second dependent on the -- first. gbind :: (GMonad m, BindInv m i j) => m i a -> (a -> m j b) -> m (Bind m i j) b -- | Remove one level of nested structure. -- -- Default implementation requires the default instance of Join. gjoin :: (GMonad m, JoinInv m i j) => m i (m j b) -> m (Join m i j) b -- | Remove one level of nested structure. -- -- Default implementation requires the default instance of Join. gjoin :: (GMonad m, Bind m i j ~ Join m i j, BindInv m i j) => m i (m j b) -> m (Join m i j) b module Control.MonadZero.Graph -- | Graph indexed monad with a monoidal zero. -- -- See the typeclassopedia -- https://wiki.haskell.org/Typeclassopedia. class GMonad m => GMonadZero (m :: p -> * -> *) where type Zero m :: p type Zero m = Unit m where { type family Zero m :: p; type Zero m = Unit m; } -- | Identity element. gzero :: GMonadZero m => m (Zero m) a -- | This is only used in Do Notation with refutable patterns. e.g.: -- --
--   do  Just a <- m
--       k a
--   
-- -- Is desugared as: -- --
--   let f (Just a) = k a
--       f _        = fail "Pattern match failure in do expression..."    
--   in m >>= k
--   
-- -- With -XApplicativeDo, there are two outstanding issues: -- -- First, This will not compile -- (https:/ghc.haskell.orgtracghcticket/13648) as the body -- statements m1 and m2 are desugared incorrectly: -- --
--   f m1 m2 k = do
--       m1
--       m2
--       k
--   
-- -- To resolve, replace m1 with _ <- m1. -- -- Second, fail must be in scope -- (https:/ghc.haskell.orgtracghcticket/13649) when -- wildcard patterns are used. The module Prelude.Graphted takes -- care of this, and custom preludes must as well. A -- GMonadFail constraint will not be added unless a -- refutable pattern is used. module Control.MonadFail.Graph -- | Graph indexed monad with failure. class GMonad m => GMonadFail (m :: p -> * -> *) where type Fail m :: p type Fail m = Unit m gfail _ = gzero where { type family Fail m :: p; type Fail m = Unit m; } -- | Fail with a message. -- -- Default implementation requires the default instance of Fail. gfail :: GMonadFail m => String -> m (Fail m) a -- | Fail with a message. -- -- Default implementation requires the default instance of Fail. gfail :: (GMonadFail m, GMonadZero m, Zero m ~ Fail m) => String -> m (Fail m) a module Control.MonadOr.Graph -- | Graph indexed monad with a monoidal operation satisfying the left -- catch law. -- -- See the typeclassopedia -- https://wiki.haskell.org/Typeclassopedia. class GMonadZero m => GMonadOr (m :: p -> * -> *) where type Or m (i :: p) (j :: p) :: p type OrInv m (i :: p) (j :: p) :: Constraint type Or m i j = Combine m i j type OrInv m i j = Inv m i j where { type family Or m (i :: p) (j :: p) :: p; type family OrInv m (i :: p) (j :: p) :: Constraint; type Or m i j = Combine m i j; type OrInv m i j = Inv m i j; } -- | An associative binary operation (<|>). gorelse :: (GMonadOr m, OrInv m i j) => m i a -> m j a -> m (Or m i j) a module Control.MonadPlus.Graph -- | Graph indexed monad with a monoidal operation satisfying the left -- distribution law. -- -- See the typeclassopedia -- https://wiki.haskell.org/Typeclassopedia. class GMonadZero m => GMonadPlus (m :: p -> * -> *) where type Plus m (i :: p) (j :: p) :: p type PlusInv m (i :: p) (j :: p) :: Constraint type Plus m i j = Combine m i j type PlusInv m i j = Inv m i j where { type family Plus m (i :: p) (j :: p) :: p; type family PlusInv m (i :: p) (j :: p) :: Constraint; type Plus m i j = Combine m i j; type PlusInv m i j = Inv m i j; } -- | An associative binary operation (mplus). gplus :: (GMonadPlus m, PlusInv m i j) => m i a -> m j a -> m (Plus m i j) a module Control.Graphted module Data.GWrapped -- | Wrap a non-indexed type constructor: newtype GWrapped (m :: * -> *) (p :: *) a GWrapped :: m a -> GWrapped a [unG] :: GWrapped a -> m a newtype Singleton i Singleton :: i -> Singleton i -- | Lift an object to GWrapped. liftG :: m a -> GWrapped m p a instance Control.Graphted.Class.Graphted (Data.GWrapped.GWrapped m) instance GHC.Base.Applicative f => Data.Pointed.Graph.GPointed (Data.GWrapped.GWrapped f) instance GHC.Base.Functor f => Data.Functor.Graph.GFunctor (Data.GWrapped.GWrapped f) instance GHC.Base.Applicative f => Control.Applicative.Graph.GApplicative (Data.GWrapped.GWrapped f) instance GHC.Base.Monad m => Control.Monad.Graph.GMonad (Data.GWrapped.GWrapped m) instance GHC.Base.Monad m => Control.MonadFail.Graph.GMonadFail (Data.GWrapped.GWrapped m) instance GHC.Base.MonadPlus m => Control.MonadZero.Graph.GMonadZero (Data.GWrapped.GWrapped m) instance GHC.Base.MonadPlus m => Control.MonadPlus.Graph.GMonadPlus (Data.GWrapped.GWrapped m) instance (GHC.Base.Alternative m, GHC.Base.MonadPlus m) => Control.MonadOr.Graph.GMonadOr (Data.GWrapped.GWrapped m) module Data.GWrappedIx -- | Wrap a two-parameter-indexed type constructor: newtype WrappedIx (m :: * -> * -> * -> *) (p :: (*, *)) a WrappedIx :: m (FstIx p) (SndIx p) a -> WrappedIx a [unIx] :: WrappedIx a -> m (FstIx p) (SndIx p) a -- | Lift an object to WrappedIx. liftIx :: m i j a -> WrappedIx m '(i, j) a instance Control.Graphted.Class.Graphted (Data.GWrappedIx.WrappedIx m) instance Data.Functor.Indexed.IxPointed f => Data.Pointed.Graph.GPointed (Data.GWrappedIx.WrappedIx f) instance Data.Functor.Indexed.IxFunctor f => Data.Functor.Graph.GFunctor (Data.GWrappedIx.WrappedIx f) instance Data.Functor.Indexed.IxApplicative f => Control.Applicative.Graph.GApplicative (Data.GWrappedIx.WrappedIx f) instance Control.Monad.Indexed.IxMonad m => Control.Monad.Graph.GMonad (Data.GWrappedIx.WrappedIx m) instance Control.Monad.Indexed.IxMonadZero m => Control.MonadFail.Graph.GMonadFail (Data.GWrappedIx.WrappedIx m) instance Control.Monad.Indexed.IxMonadZero m => Control.MonadZero.Graph.GMonadZero (Data.GWrappedIx.WrappedIx m) instance Control.Monad.Indexed.IxMonadPlus m => Control.MonadPlus.Graph.GMonadPlus (Data.GWrappedIx.WrappedIx m) module Prelude.Graphted fmap :: GFunctor f => (a -> b) -> f i a -> f (Fmap f i) b (<$) :: GFunctor f => b -> f i a -> f (Replace f i) b infixl 4 <$ (<$>) :: GFunctor f => (a -> b) -> f i a -> f (Fmap f i) b pure :: GPointed f => a -> f (Pure f) a (<*>) :: (GApplicative f, ApplyInv f i j) => f i (a -> b) -> f j a -> f (Apply f i j) b infixl 4 <*> (*>) :: (GApplicative f, ThenInv f i j) => f i a -> f j b -> f (Then f i j) b infixl 4 *> (<*) :: (GApplicative f, ButInv f i j) => f i a -> f j b -> f (But f i j) a infixl 4 <* return :: GPointed m => a -> m (Pure m) a (>>=) :: (GMonad m, BindInv m i j) => m i a -> (a -> m j b) -> m (Bind m i j) b infixl 1 >>= (=<<) :: (GMonad m, BindInv m i j) => (a -> m j b) -> m i a -> m (Bind m i j) b infixr 1 =<< (>>) :: (GApplicative m, ThenInv m i j) => m i a -> m j b -> m (Then m i j) b infixl 1 >> fail :: GMonadFail m => String -> m (Fail m) a zero :: GMonadZero m => m (Zero m) a (<+>) :: (GMonadPlus f, PlusInv f i j) => f i a -> f j a -> f (Plus f i j) a (<|>) :: (GMonadOr f, OrInv f i j) => f i a -> f j a -> f (Or f i j) a (<**>) :: (GApplicative f, _) => f i1 a -> f i2 (a -> b) -> f (Apply f (Apply f (Pure f) i1) i2) b infixl 4 <**> liftA :: (GApplicative f, _) => (a -> b) -> f i1 a -> f (Apply f (Pure f) i1) b liftA2 :: (GApplicative f, _) => (a1 -> a2 -> b) -> f i1 a1 -> f i2 a2 -> f (LiftA2 f i1 i2) b liftA3 :: (GApplicative f, _) => (a1 -> a2 -> a3 -> b) -> f i1 a1 -> f i2 a2 -> f i3 a3 -> f (Apply f (LiftA2 f i1 i2) i3) b join :: (GMonad m, JoinInv m i j) => m i (m j b) -> m (Join m i j) b liftM :: (GApplicative m, _) => (t -> b) -> m j t -> m (Fmap m j) b liftM2 :: (GApplicative m, _) => (t1 -> t -> b) -> m i1 t1 -> m i t -> m (Apply m (Fmap m i1) i) b liftM3 :: (GApplicative m, _) => (t2 -> t1 -> t -> b) -> m i2 t2 -> m i1 t1 -> m i t -> m (Apply m (Apply m (Fmap m i2) i1) i) b liftM4 :: (GApplicative m, _) => (t3 -> t2 -> t1 -> t -> b) -> m i3 t3 -> m i2 t2 -> m i1 t1 -> m i t -> m (Apply m (Apply m (Apply m (Fmap m i3) i2) i1) i) b liftM5 :: (GApplicative m, _) => (t4 -> t3 -> t2 -> t1 -> t -> b) -> m i4 t4 -> m i3 t3 -> m i2 t2 -> m i1 t1 -> m i t -> m (Apply m (Apply m (Apply m (Apply m (Fmap m i4) i3) i2) i1) i) b ap :: (GApplicative m, _) => m i (t -> b) -> m j t -> m (Apply m (Fmap m i) j) b mapM_ :: (GApplicative m, Foldable t, Apply m (Fmap m i) (Pure m) ~ Pure m, _) => (a1 -> m i a) -> t a1 -> m (Pure m) () sequence_ :: (GApplicative m, Foldable t, Apply m (Fmap m i) (Pure m) ~ Pure m, _) => t (m i a) -> m (Pure m) ()