graphted 0.1.0.1 → 0.1.0.2
raw patch · 10 files changed
+100/−22 lines, 10 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.GWrapped: [unGwrap] :: GWrapped a -> m a
- Data.GWrapped: unM :: GWrapped m p a -> m a
+ Data.GWrapped: [unG] :: GWrapped a -> m a
- Data.GWrapped: liftG :: m a -> GWrapped m () a
+ Data.GWrapped: liftG :: m a -> GWrapped m p a
Files
- graphted.cabal +1/−1
- src/Control/Applicative/Graph.hs +20/−3
- src/Control/Monad/Graph.hs +12/−0
- src/Control/MonadFail/Graph.hs +8/−1
- src/Control/MonadOr/Graph.hs +8/−0
- src/Control/MonadPlus/Graph.hs +8/−0
- src/Control/MonadZero/Graph.hs +6/−0
- src/Data/Functor/Graph.hs +12/−0
- src/Data/GWrapped.hs +9/−13
- src/Data/Pointed/Graph.hs +16/−4
graphted.cabal view
@@ -1,5 +1,5 @@ name: graphted-version: 0.1.0.1+version: 0.1.0.2 synopsis: Graph indexed monads. -- description: TODO homepage: https://github.com/aaronfriel/graphted#readme
src/Control/Applicative/Graph.hs view
@@ -26,29 +26,46 @@ import Data.Functor.Graph import Data.Pointed.Graph +-- | Graph indexed applicative functor. class (GFunctor f, GPointed f) => GApplicative (f :: p -> * -> *) where++ -- | The apply operation ('<*>') on the graph index.+ --+ -- Default instance: @Apply f i j = 'Combine' f i j@ type family Apply f (i :: p) (j :: p) :: p type instance Apply f i j = Combine f i j + -- | The then operation ('*>') on the graph index.+ --+ -- Default instance: @'Then' f i j = 'Apply' f ('Fconst' f i) j@ type family Then f (i :: p) (j :: p) :: p type instance Then f i j = Apply f (Fconst f i) j + -- | The but operation ('<*') on the graph index.+ --+ -- Default instance: @But f i j = 'Apply' f ('Apply' f ('Pure' f) i) j@ type family But f (i :: p) (j :: p) :: p type instance But f i j = Apply f (Apply f (Pure f) i) j - -- <*>+ -- | Sequential application ('<*>'). gap :: Inv f i j => f i (a -> b) -> f j a -> f (Apply f i j) b - -- *>+ -- | Sequence actions, discarding the value of the first argument ('*>').+ --+ -- Default implementation requires the default instance of 'Then'. {-# INLINE gthen #-} gthen :: Inv f i j => f i a -> f j b -> f (Then f i j) b default gthen :: (Apply f (Fconst f i) j ~ Then f i j, Inv f (Fconst f i) j) => f i a -> f j b -> f (Then f i j) b gthen a b = (id `gconst` a) `gap` b - -- <*+ -- | Sequence actions, discarding values of the second argument ('<*').+ --+ -- Default implementation requires the default instance of 'But'. {-# INLINE gbut #-} gbut :: Inv f i j => f i a -> f j b -> f (But f i j) a default gbut :: (Apply f (Apply f (Pure f) i) j ~ But f i j, Inv f (Pure f) i, Inv f (Apply f (Pure f) i) j) => f i a -> f j b -> f (But f i j) a gbut a b = gpoint const `gap` a `gap` b++ {-# MINIMAL gap #-}
src/Control/Monad/Graph.hs view
@@ -25,15 +25,27 @@ import Control.Applicative.Graph +-- | Graph indexed monad. class GApplicative m => GMonad (m :: p -> * -> *) where++ -- | The apply operation ('>>=') on the graph index.+ --+ -- Default instance: @Bind m i j = 'Combine' m i j@ type family Bind m (i :: p) (j :: p) :: p type instance Bind m i j = Combine m i j + -- | The join operation ('Control.Monad.join') on the graph index.+ --+ -- Default instance: @Join m i j = 'Bind' m i j@ type family Join m (i :: p) (j :: p) :: p type instance Join m i j = Bind m i j + -- | Sequentially compose two actions, with the second dependent on the first. gbind :: Inv 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'. {-# INLINE gjoin #-} gjoin :: (Inv m i j) => m i (m j b) -> m (Join m i j) b default gjoin :: (Bind m i j ~ Join m i j, Inv m i j) => m i (m j b) -> m (Join m i j) b
src/Control/MonadFail/Graph.hs view
@@ -26,11 +26,18 @@ import Control.Monad.Graph import Control.MonadZero.Graph +-- | Graph indexed monad with failure. class GMonad m => GMonadFail (m :: p -> * -> *) where+ -- | The unit failure element of the index.+ --+ -- Default instance: @Fail m = 'Unit' m@ type family Fail m :: p type instance Fail m = Unit m + -- | Fail with a message.+ --+ -- Default implementation requires the default instance of 'Fail'.+ {-# INLINE gfail #-} gfail :: String -> m (Fail m) a- default gfail :: (GMonadZero m, Zero m ~ Fail m) => String -> m (Fail m) a gfail _ = gzero
src/Control/MonadOr/Graph.hs view
@@ -25,8 +25,16 @@ import Control.MonadZero.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+ + -- | The or operation ('<|>') on the graph index.+ --+ -- Default instance: @Or m i j = 'Combine' m i j@ type family Or m (i :: p) (j :: p) :: p type instance Or m i j = Combine m i j + -- | An associative binary operation ('<|>'). gorelse :: m i a -> m j a -> m (Or m i j) a
src/Control/MonadPlus/Graph.hs view
@@ -25,8 +25,16 @@ import Control.MonadZero.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++ -- | The or operation ('mplus') on the graph index.+ --+ -- Default instance: @Plus m i j = 'Combine' m i j@ type family Plus m (i :: p) (j :: p) :: p type instance Plus m i j = Combine m i j + -- | An associative binary operation ('mplus'). gplus :: m i a -> m j a -> m (Plus m i j) a
src/Control/MonadZero/Graph.hs view
@@ -25,8 +25,14 @@ import Control.Monad.Graph +-- | Graph indexed monad with a monoidal zero.+--+-- See the typeclassopedia <https://wiki.haskell.org/Typeclassopedia>. class GMonad m => GMonadZero (m :: p -> * -> *) where++ -- | The zero element ('mzero', 'mempty') of the graph index. type family Zero m :: p type instance Zero m = Unit m + -- | Identity element. gzero :: m (Zero m) a
src/Data/Functor/Graph.hs view
@@ -18,15 +18,27 @@ module Data.Functor.Graph where +-- | Graph indexed functor. class GFunctor (f :: p -> * -> *) where++ -- | The fmap operation ('fmap') on the graph index.+ --+ -- Default instance: @Fmap f i = i@ type family Fmap f (i :: p) :: p type instance Fmap f i = i + -- | The fconst operation ('<$') on the graph index.+ --+ -- Default instance: @Fconst f i = 'Fmap' f i@ type family Fconst f (i :: p) :: p type instance Fconst f i = Fmap f i + -- | Map a function over over the functor ('fmap'). gmap :: (a -> b) -> f i a -> f (Fmap f i) b + -- | Replace all values with a constant ('<$').+ --+ -- Default implementation requires the default instance of 'Fconst'. {-# INLINABLE gconst #-} gconst :: a -> f i b -> f (Fconst f i) a default gconst :: (Fconst f i ~ Fmap f i) => a -> f i b -> f (Fconst f i) a
src/Data/GWrapped.hs view
@@ -1,14 +1,12 @@ {- | Module : Data.GWrapped-Description :+Description : Wrapped type constructors (typically Monad), graphted. Copyright : (c) Aaron Friel License : BSD-3- Maintainer : Aaron Friel <mayreply@aaronfriel.com> Stability : unstable Portability : portable - -} {-# LANGUAGE GADTs #-}@@ -24,13 +22,11 @@ import Control.Monad (MonadPlus (..)) import Data.Type.Equality (type (~~)) --- Wrapping a non-indexed type constructor:-newtype GWrapped (m :: * -> *) (p :: *) a = GWrapped { unGwrap :: m a }--unM :: GWrapped m p a -> m a-unM (GWrapped m) = m+-- | Wrap a non-indexed type constructor:+newtype GWrapped (m :: * -> *) (p :: *) a = GWrapped { unG :: m a } -liftG :: m a -> GWrapped m () a+-- | Lift an object to 'GWrapped'.+liftG :: m a -> GWrapped m p a liftG = GWrapped instance Graphted (GWrapped m) where@@ -42,8 +38,8 @@ gpoint' = GWrapped . pure instance Functor f => GFunctor (GWrapped f) where- gmap f = GWrapped . fmap f . unGwrap- gconst f = GWrapped . ((<$) f) . unGwrap+ gmap f = GWrapped . fmap f . unG+ gconst f = GWrapped . ((<$) f) . unG instance Applicative f => GApplicative (GWrapped f) where gap (GWrapped m) (GWrapped k) = GWrapped $ m <*> k@@ -51,8 +47,8 @@ gbut (GWrapped m) (GWrapped k) = GWrapped $ m <* k instance Monad m => GMonad (GWrapped m) where- gbind (GWrapped m) k = GWrapped $ m >>= unM . k- gjoin (GWrapped m) = GWrapped $ m >>= unM+ gbind (GWrapped m) k = GWrapped $ m >>= unG . k+ gjoin (GWrapped m) = GWrapped $ m >>= unG instance Monad m => GMonadFail (GWrapped m) where gfail = GWrapped . fail
src/Data/Pointed/Graph.hs view
@@ -20,15 +20,27 @@ import Control.Graphted.Class --- | Pointed functor.+-- | Graph indexed pointed functor. class GPointed (f :: p -> * -> *) where+ + -- | The pure element of the graph index. type family Pure f :: p type instance Pure f = Unit f - -- | Accessible only with type applications.- gpoint' :: forall t a. a -> f t a-+ -- | Return a pointed functor indexed by the 'Pure' type instance ('pure').+ --+ -- >>> :t gpoint @_ @(GWrapped Maybe) "Hello, World"+ -- :: GWrapped Maybe () [Char] gpoint :: forall a. a -> f (Pure f) a gpoint = gpoint' @p @f @(Pure f)++ -- | Return a pointed functor indexed by a type 't' in the domain of 'p'.+ --+ -- Accessible with type applications, e.g.:+ -- + -- >>> :t gpoint' @_ @(GWrapped Maybe) @Int+ -- gpoint' @_ @(GWrapped Maybe) @Int :: a -> GWrapped Maybe Int a+ -- + gpoint' :: forall t a. a -> f t a {-# MINIMAL gpoint' #-}