graphted 0.2.5.1 → 0.3.0.0
raw patch · 7 files changed
+80/−32 lines, 7 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Functor.Graph: gconst :: (GFunctor f, Fconst f i ~ Fmap f i) => a -> f i b -> f (Fconst f i) a
- Data.Functor.Graph: type Fconst f i = Fmap f i;
+ Control.Applicative.Graph: 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
+ Control.Applicative.Graph: type LiftA2 f i j = Apply f (Fmap f i) j;
+ Control.Applicative.Graph: type LiftA2Inv f i j = ApplyInv f i j;
+ Data.Functor.Graph: greplace :: (GFunctor f, Replace f i ~ Fmap f i) => a -> f i b -> f (Replace f i) a
+ Data.Functor.Graph: type Replace f i = Fmap f i;
- Control.Applicative.Graph: 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 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 Then f i j = Apply f (Fconst f i) j type ThenInv f i j = ApplyInv f i j type But f i j = Apply f (Apply f (Pure f) i) j type ButInv f i j = ApplyInv f i j gthen a b = (id `gconst` a) `gap` b gbut a b = gpure const `gap` a `gap` b where {
+ Control.Applicative.Graph: 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 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 Then f i j = Apply f (Replace 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 = (id `greplace` a) `gap` b gbut = gliftA2 const where {
- Control.Applicative.Graph: gbut :: (GApplicative f, Apply f (Apply f (Pure f) i) j ~ But f i j, ApplyInv f (Pure f) i, ApplyInv f (Apply f (Pure f) i) j, ButInv f (Apply f (Pure f) i) j) => f i a -> f j b -> f (But f i j) a
+ Control.Applicative.Graph: 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
- Control.Applicative.Graph: gthen :: (GApplicative f, Apply f (Fconst f i) j ~ Then f i j, ApplyInv f (Fconst f i) j, ThenInv f (Fconst f i) j) => f i a -> f j b -> f (Then f i j) b
+ Control.Applicative.Graph: gthen :: (GApplicative f, Apply f (Replace f i) j ~ Then f i j, ApplyInv f (Replace f i) j, ThenInv f (Replace f i) j) => f i a -> f j b -> f (Then f i j) b
- Control.Applicative.Graph: type But f i j = Apply f (Apply f (Pure f) i) j;
+ Control.Applicative.Graph: type But f i j = LiftA2 f i j;
- Control.Applicative.Graph: type Then f i j = Apply f (Fconst f i) j;
+ Control.Applicative.Graph: type Then f i j = Apply f (Replace f i) j;
- Data.Functor.Graph: class GFunctor (f :: p -> * -> *) where type Fmap f (i :: p) :: p type Fconst f (i :: p) :: p type Fmap f i = i type Fconst f i = Fmap f i gconst = gmap . const where {
+ Data.Functor.Graph: class GFunctor (f :: p -> * -> *) where type Fmap f (i :: p) :: p type Replace f (i :: p) :: p type Fmap f i = i type Replace f i = Fmap f i greplace = gmap . const where {
- Data.Functor.Graph: type family Fconst f (i :: p) :: p;
+ Data.Functor.Graph: type family Replace f (i :: p) :: p;
- Prelude.Graphted: (<$) :: GFunctor f => b -> f i a -> f (Fconst f i) b
+ Prelude.Graphted: (<$) :: GFunctor f => b -> f i a -> f (Replace f i) b
Files
- graphted.cabal +2/−2
- src/Control/Applicative/Graph.hs +27/−11
- src/Control/MonadFail/Graph.hs +36/−1
- src/Data/Functor/Graph.hs +9/−9
- src/Data/GWrapped.hs +2/−2
- src/Data/GWrappedIx.hs +2/−5
- src/Prelude/Graphted.hs +2/−2
graphted.cabal view
@@ -1,5 +1,5 @@ name: graphted-version: 0.2.5.1+version: 0.3.0.0 synopsis: Graph indexed monads. -- description: TODO homepage: https://github.com/aaronfriel/graphted#readme@@ -8,7 +8,7 @@ author: Aaron Friel maintainer: mayreply@aaronfriel.com copyright: BSD3-category: Control+category: Control, Comonads, Monads build-type: Simple extra-source-files: README.md cabal-version: >=1.10
src/Control/Applicative/Graph.hs view
@@ -44,11 +44,23 @@ type family ApplyInv f (i :: p) (j :: p) :: Constraint type instance ApplyInv f i j = Inv f i j + -- | The 'liftA2' operation on the graph index.+ --+ -- Default instance: @Lift f i j = 'Apply' f ('Apply' f ('Pure' f) i) j@ + type family LiftA2 f (i :: p) (j :: p) :: p+ type instance LiftA2 f i j = Apply f (Fmap f i) j++ -- | An invariant on the indexes of 'But'.+ --+ -- Default instance: @ButInv m i j = 'ApplyInv' m i j@+ type family LiftA2Inv f (i :: p) (j :: p) :: Constraint+ type instance LiftA2Inv f i j = ApplyInv f i j+ -- | The then operation ('*>') on the graph index. --- -- Default instance: @'Then' f i j = 'Apply' f ('Fconst' f i) j@ + -- Default instance: @'Then' f i j = 'Apply' f ('Replace' f i) j@ type family Then f (i :: p) (j :: p) :: p- type instance Then f i j = Apply f (Fconst f i) j+ type instance Then f i j = Apply f (Replace f i) j -- | An invariant on the indexes of 'Then'. --@@ -58,9 +70,9 @@ -- | The but operation ('<*') on the graph index. --- -- Default instance: @But f i j = 'Apply' f ('Apply' f ('Pure' f) i) j@ + -- Default instance: @But f i j = 'LiftA2' 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+ type instance But f i j = LiftA2 f i j -- | An invariant on the indexes of 'But'. --@@ -71,25 +83,29 @@ -- | Sequential application ('<*>'). gap :: ApplyInv f i j => f i (a -> b) -> f j a -> f (Apply f i j) b + -- | Lift a binary function to actions.+ --+ gliftA2 :: LiftA2Inv f i j => (a -> b -> c) -> f i a -> f j b -> f (LiftA2 f i j) c + default gliftA2 :: (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+ gliftA2 f x = gap (gmap f x)+ -- | Sequence actions, discarding the value of the first argument ('*>'). -- -- Default implementation requires the default instance of 'Then'. {-# INLINE gthen #-} gthen :: ThenInv 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, ApplyInv f (Fconst f i) j, ThenInv f (Fconst f i) j)+ default gthen :: (Apply f (Replace f i) j ~ Then f i j, ApplyInv f (Replace f i) j, ThenInv f (Replace f i) j) => f i a -> f j b -> f (Then f i j) b- gthen a b = (id `gconst` a) `gap` b+ gthen a b = (id `greplace` a) `gap` b -- | Sequence actions, discarding values of the second argument ('<*'). -- -- Default implementation requires the default instance of 'But'. {-# INLINE gbut #-} gbut :: ButInv 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, - ApplyInv f (Pure f) i, - ApplyInv f (Apply f (Pure f) i) j,- ButInv f (Apply f (Pure f) i) j)+ default gbut :: (LiftA2 f i j ~ But f i j, LiftA2Inv f i j) => f i a -> f j b -> f (But f i j) a- gbut a b = gpure const `gap` a `gap` b+ gbut = gliftA2 const {-# MINIMAL gap #-}
src/Control/MonadFail/Graph.hs view
@@ -1,6 +1,6 @@ {- | Module : Control.MonadFail.Graph-Description : Graph indexed monads with failure+Description : Graph indexed monads with failure. Copyright : (c) Aaron Friel License : BSD-3 @@ -8,7 +8,42 @@ Stability : unstable Portability : portable +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.org/trac/ghc/ticket/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.org/trac/ghc/ticket/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.+ -}+ {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE FlexibleContexts #-}
src/Data/Functor/Graph.hs view
@@ -27,19 +27,19 @@ type family Fmap f (i :: p) :: p type instance Fmap f i = i - -- | The fconst operation ('<$') on the graph index.+ -- | The Replace 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+ -- Default instance: @Replace f i = 'Fmap' f i@ + type family Replace f (i :: p) :: p+ type instance Replace 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- gconst = gmap . const+ -- Default implementation requires the default instance of 'Replace'.+ {-# INLINABLE greplace #-}+ greplace :: a -> f i b -> f (Replace f i) a+ default greplace :: (Replace f i ~ Fmap f i) => a -> f i b -> f (Replace f i) a+ greplace = gmap . const
src/Data/GWrapped.hs view
@@ -49,10 +49,10 @@ instance Functor f => GFunctor (GWrapped f) where gmap f = GWrapped . fmap f . unG- gconst f = GWrapped . ((<$) f) . unG+ greplace f = GWrapped . ((<$) f) . unG instance Applicative f => GApplicative (GWrapped f) where- type But (GWrapped m) i j = i+ type But (GWrapped f) i j = i gap (GWrapped m) (GWrapped k) = GWrapped $ m <*> k gthen (GWrapped m) (GWrapped k) = GWrapped $ m *> k gbut (GWrapped m) (GWrapped k) = GWrapped $ m <* k
src/Data/GWrappedIx.hs view
@@ -27,9 +27,6 @@ import Control.Monad.Indexed import Data.Functor.Indexed -import Control.Applicative (Alternative (..))-import Control.Monad (MonadPlus (..))- import GHC.Exts (Any) -- | Wrap a two-parameter-indexed type constructor:@@ -72,10 +69,10 @@ instance IxFunctor f => GFunctor (WrappedIx f) where gmap f = WrappedIx . imap f . unIx- gconst a = WrappedIx . imap (const a) . unIx+ greplace a = WrappedIx . imap (const a) . unIx instance IxApplicative f => GApplicative (WrappedIx f) where- type But (WrappedIx m) l r = '( FstIx l, SndIx r )+ type But (WrappedIx f) l r = '( FstIx l, SndIx r ) gap (WrappedIx m) (WrappedIx k) = WrappedIx $ m <<*>> k gthen (WrappedIx m) (WrappedIx k) = WrappedIx $ m *>> k gbut (WrappedIx m) (WrappedIx k) = WrappedIx $ m <<* k
src/Prelude/Graphted.hs view
@@ -59,8 +59,8 @@ fmap :: GFunctor f => (a -> b) -> f i a -> f (Fmap f i) b fmap = gmap -(<$) :: GFunctor f => b -> f i a -> f (Fconst f i) b-(<$) = gconst+(<$) :: GFunctor f => b -> f i a -> f (Replace f i) b+(<$) = greplace (<$>) :: GFunctor f => (a -> b) -> f i a -> f (Fmap f i) b (<$>) = fmap