packages feed

polysemy-methodology-composite (empty) → 0.1.0.0

raw patch · 5 files changed

+190/−0 lines, 5 filesdep +basedep +composite-basedep +polysemy

Dependencies added: base, composite-base, polysemy, polysemy-extra, polysemy-methodology, polysemy-vinyl, vinyl

Files

+ ChangeLog.md view
@@ -0,0 +1,9 @@+# Changelog for polysemy-composite++## v0.1.1.0++* Add `runInputCase'`.++## v0.1.0.0++* Add interpreting and reinterpreting versions of `runCoRecMethodologyAsCases` and `diffractMethodology`.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Daniel Firth (c) 2020++All rights reserved.++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 Daniel Firth nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++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 POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,6 @@+# polysemy-methodology-composite++Functions for using+[polysemy-methodology](https://hackage.haskell.org/package/polysemy-methodology)+in conjunction with+[composite](https://hackage.haskell.org/package/composite-base).
+ polysemy-methodology-composite.cabal view
@@ -0,0 +1,40 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.2.+--+-- see: https://github.com/sol/hpack++name:           polysemy-methodology-composite+version:        0.1.0.0+synopsis:       Functions for using polysemy-methodology with composite.+category:       Polysemy Vinyl Composite+author:         Daniel Firth+maintainer:     dan.firth@homotopic.tech+copyright:      dan.firth@homotopic.tech+license:        MIT+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+  type: git+  location: https://gitlab.com/homotopic-tech/polysemy-methodology-composite++library+  exposed-modules:+      Polysemy.Methodology.Composite+  other-modules:+      Paths_polysemy_methodology_composite+  hs-source-dirs:+      src+  build-depends:+      base >=4.7 && <5+    , composite-base+    , polysemy+    , polysemy-extra >=0.1.1.0+    , polysemy-methodology >=0.1.6.0+    , polysemy-vinyl >=0.1.2.0+    , vinyl+  default-language: Haskell2010
+ src/Polysemy/Methodology/Composite.hs view
@@ -0,0 +1,105 @@+{- |+   Module     : Polysemy.Methodology.Composite+   License    : MIT+   Maintainer : dan.firth@homotopic.tech+   Stability  : experimental++Functions for combining polysemy-methodology with composite.+-}+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE BlockArguments      #-}+{-# LANGUAGE DataKinds           #-}+{-# LANGUAGE FlexibleContexts    #-}+{-# LANGUAGE LambdaCase          #-}+{-# LANGUAGE GADTs               #-}+{-# LANGUAGE PolyKinds           #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications    #-}+{-# LANGUAGE TypeOperators       #-}+module Polysemy.Methodology.Composite (+  runCoRecMethodologyAsCases+, runCoRecMethodologyAsCases'+, diffractMethodology+, diffractMethodology'+, runInputCase'+) where++import Control.Arrow+import Composite.CoRecord+import Data.Vinyl+import Polysemy+import Polysemy.Extra+import Polysemy.Input+import Polysemy.Methodology++-- | 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.+--+-- @since 0.1.0.0+runCoRecMethodologyAsCases :: forall f zs c x xs r a.+                              (zs ~ (x ': xs), RecApplicative zs, Members '[Input (Cases' f zs c)] r)+                           => Sem (Methodology (CoRec f zs) c ': r) a+                              -- ^ The Methodology to decompose.+                           -> Sem r a+runCoRecMethodologyAsCases = interpret \case+  Process b -> do+    x <- input @(Cases' f zs c)+    return $ foldCoRec x b+{-# INLINE runCoRecMethodologyAsCases #-}++-- | Reinterpreting version of `runCoRecMethodologyAsCases`.+--+--+-- @since 0.1.0.0+runCoRecMethodologyAsCases' :: forall f zs c x xs r a.+                               (zs ~ (x ': xs), RecApplicative zs)+                            => Sem (Methodology (CoRec f zs) c ': r) a+                               -- ^ The Methodology to decompose.+                            -> Sem (Input (Cases' f zs c) ': r) a+runCoRecMethodologyAsCases' = reinterpret \case+  Process b -> do+    x <- input @(Cases' f zs c)+    return $ foldCoRec x b+{-# INLINE runCoRecMethodologyAsCases' #-}++-- | Diffraction is a combination of a `cutMethodology'`, an `mconcatMethodology'` and a `runCoRecMethodologyAsCases`.+--+-- This effectively allows you to make several ad-hoc constructors for d and fully consumes the second half of the cut.+-- This turns out to be quite a good way to start a simple pipeline.+--+-- @since 0.1.0.0+diffractMethodology :: forall b f zs d x xs r a.+                       (Monoid d, zs ~ (x ': xs)+                      , RecApplicative zs+                      , Members '[ Methodology b [CoRec f zs]+                                 , Input (Cases' f zs d)] r)+                    => Sem (Methodology b d ': r) a+                       -- ^ The Methodology to decompose.+                    -> Sem r a+diffractMethodology = cutMethodology' @b @[CoRec f zs] @d+                  >>> reinterpretUnder mconcatMethodology'+                  >>> reinterpretUnder runCoRecMethodologyAsCases'+                  >>> subsume >>> subsume+{-# INLINE diffractMethodology #-}++-- | Reinterpreting version of `diffractMethodology`.+--+-- @since 0.1.0.0+diffractMethodology' :: forall b f zs d x xs r a.+                        (Monoid d, zs ~ (x ': xs), RecApplicative zs)+                     => Sem (Methodology b d ': r) a+                        -- ^ The Methodology to decompose.+                     -> Sem (Methodology b [CoRec f zs] ': Input (Cases' f zs d) ': r) a+diffractMethodology' = cutMethodology' @b @[CoRec f zs] @d+                   >>> reinterpretUnder mconcatMethodology'+                   >>> reinterpretUnder runCoRecMethodologyAsCases'+{-# INLINE diffractMethodology' #-}++-- | Run a `Case'` using `runInputConst` and a function eliminating the `Case'`.+--+-- @since 0.1.1.0+runInputCase' :: forall b f t r a.+                 (f b -> t)+              -> Sem (Input (Case' f t b) ': r) a+              -> Sem r a+runInputCase' f = runInputConst (Case' f)