polysemy-methodology-composite 0.1.3.0 → 0.1.4.0
raw patch · 4 files changed
+58/−2 lines, 4 files
Files
- ChangeLog.md +4/−0
- README.md +4/−0
- polysemy-methodology-composite.cabal +1/−1
- src/Polysemy/Methodology/Composite.hs +49/−1
ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for polysemy-composite +## v0.1.4.0++* Add `runMethodologyRMap`, `pickCoRecConstructor`, `fmapCMethodology`.+ ## v0.1.3.0 * Add `separateRecInitial`, `stripRecInitial`, `stripRecInitial`, `endRecInitial`.
README.md view
@@ -4,3 +4,7 @@ [polysemy-methodology](https://hackage.haskell.org/package/polysemy-methodology) in conjunction with [composite](https://hackage.haskell.org/package/composite-base).++In order make best use of these, you should also bring in+[polysemy-vinyl](https://hackage.haskell.org/package/polysemy-vinyl)+and [polysemy-extra](https://hackage.haskell.org/package/polysemy-extra).
polysemy-methodology-composite.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: polysemy-methodology-composite-version: 0.1.3.0+version: 0.1.4.0 synopsis: Functions for using polysemy-methodology with composite. category: Polysemy Vinyl Composite author: Daniel Firth
src/Polysemy/Methodology/Composite.hs view
@@ -13,15 +13,18 @@ {-# LANGUAGE LambdaCase #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE PolyKinds #-}+{-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeOperators #-} module Polysemy.Methodology.Composite (- runCoRecMethodologyAsCases+ runMethodologyRmap+, runCoRecMethodologyAsCases , runCoRecMethodologyAsCases' , diffractMethodology , diffractMethodology' , runInputCase'+, pickCoRecConstructor , separateRecInitial , separateRecInitial' , stripRecInitial@@ -32,6 +35,8 @@ , separateRecTerminal' , stripRecTerminal , endRecTerminal+, fmapCMethodology+, fmapCMethodology' ) where import Control.Arrow@@ -43,6 +48,17 @@ import Polysemy.Input import Polysemy.Methodology +-- | Run a `Methodology` between two `Rec`s according to a natural transformation+-- between the interpretation functors.+--+-- @since 0.1.4.0+runMethodologyRmap :: forall f g xs r a. RMap xs =>+ (forall y. f y -> g y)+ -> Sem (Methodology (Rec f xs) (Rec g xs) ': r) a+ -> Sem r a+runMethodologyRmap f = runMethodologyPure (rmap f)+{-# INLINE runMethodologyRmap #-}+ -- | Run a `Methodology` from a `CoRec` to an `Input` of `Cases'`. You can then use `Polysemy.Vinyl.separateRecInput` and `Polysemy.Vinyl.stripRecInput` -- to deal with the cases individually. --@@ -116,6 +132,17 @@ runInputCase' f = runInputConst (Case' f) {-# INLINE runInputCase' #-} +-- | Take a `Methodology` into a `CoRec` and choose a constructor.+--+-- @since 0.1.4.0+pickCoRecConstructor :: forall x f b xs r a. x ∈ xs =>+ Sem (Methodology b (CoRec f xs) ': r) a+ -> Sem (Methodology b (f x) ': r) a+pickCoRecConstructor = cutMethodology'+ >>> rotateEffects2+ >>> runMethodologyPure CoVal+{-# INLINE pickCoRecConstructor #-}+ -- | Factor a `Methodology` with a `Rec` in the result by a `Methodology` to the first variable. -- -- @since 0.1.3.0@@ -244,3 +271,24 @@ endRecTerminal = interpret \case Process _ -> return mempty {-# INLINE endRecTerminal #-}++-- | Like `fmapMethodology`, but used with a `Compose`d functor to strip the top+-- layer from the functor.+--+-- @since 0.1.4.0+fmapCMethodology :: forall f g h b c r a. Traversable f =>+ Sem (Methodology ((f :. g) b) ((f :. h) c) ': r) a+ -> Sem (Methodology (g b) (h c) ': r) a+fmapCMethodology = reinterpret \case+ Process b -> Compose <$> traverse (process @(g b) @(h c)) (getCompose b)+{-# INLINE fmapCMethodology #-}++-- | Reinterpreting version of `fmapCMethodology`.+--+-- @since 0.1.4.0+fmapCMethodology' :: forall f g h b c r a. Traversable f =>+ Sem (Methodology ((f :. g) b) ((f :. h) c) ': r) a+ -> Sem (Methodology (g b) (h c) ': r) a+fmapCMethodology' = reinterpret \case+ Process b -> Compose <$> traverse (process @(g b) @(h c)) (getCompose b)+{-# INLINE fmapCMethodology' #-}