composite-xstep (empty) → 0.1.0.0
raw patch · 5 files changed
+154/−0 lines, 5 filesdep +basedep +composite-basedep +vinyl
Dependencies added: base, composite-base, vinyl
Files
- ChangeLog.md +5/−0
- LICENSE +30/−0
- README.md +23/−0
- composite-xstep.cabal +38/−0
- src/Composite/XStep.hs +58/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Changelog for composite-xstep++## (v0.1.0.0)++* Initial commit - Higher kinded ReaderT transformer pattern for composite records.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (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 Author name here 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,23 @@+# composite-xstep++This package provides a specific XRec pattern for [composite](https://hackage.haskell.org/package/composite) records, where the interpretation functor is isomorphic to `ReaderT r m`.++For example++```+import Path+import Composite.Record+import Composite.TH++withLensesAndProxies [d|+ type FPath = "path" :-> Path Rel File+ type FPath2 = "path2" :-> Path Rel File+ |]++type A = '[FPath, FPath2]++foo :: MonadThrow m => XStep m FilePath A+foo = parseRelDir+ ::& stripProperPrefix $(mkRelFile "foo") =<< parseRelDir+ ::& XRNil+```
+ composite-xstep.cabal view
@@ -0,0 +1,38 @@+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: composite-xstep+version: 0.1.0.0+synopsis: ReaderT transformer pattern for higher kinded composite data.+description: ReaderT transformer pattern for higher kinded composite data.+category: Data Structures+author: Daniel Firth+maintainer: dan.firth@homotopic.tech+copyright: 2020 Daniel Firth+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/composite-xstep++library+ exposed-modules:+ Composite.XStep+ other-modules:+ Paths_composite_xstep+ hs-source-dirs:+ src+ ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints+ build-depends:+ base >=4.7 && <5+ , composite-base+ , vinyl+ default-language: Haskell2010
+ src/Composite/XStep.hs view
@@ -0,0 +1,58 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{- |+ Module : Composite.XStep+ License : MIT+ Stability : experimental++Tuple functions for composite records, inspired by relude.+-}++module Composite.XStep (+ RSource(runSource)+, RSource'+, XStep+, XStep'+, runSourceI+, runXStep+, prependXStep+) where++import Composite.Record+import Data.Functor.Identity+import Data.Vinyl+import Data.Vinyl.TypeLevel+import Data.Vinyl.XRec++-- | An `RSource` is simply a `ReaderT` transformer. This is a uniquely named+-- type as composte and vinyl aren't compatible via the `IsoHKD` interface due+-- to the way that `(:->)` is defined.+newtype RSource r m a = RSource { runSource :: r -> m a }++-- | The special case where the environment is a `Record`.+type RSource' r = RSource (Record r)++instance Functor m => IsoHKD (RSource r m) (s :-> a) where+ type HKD (RSource r m) (s :-> a) = r -> m a+ unHKD f = RSource $ fmap Val . f+ toHKD (RSource f) = fmap getVal . f++-- | An `XStep` is a n `XRec` with an `RSource`. The type is eta-reduced, but in practice signatures will be written `XStep m a b` to represent a Kleisli arrow from a to m b.+type XStep m a = XRec (RSource a m)++-- | The special case where the environment is a `Record`.+type XStep' m a = XStep m (Record a)++-- | Run an `RSource` against a `Record` and pull out the underlying functor.+runSourceI :: Functor m => RSource r m a -> r -> m (Identity a)+runSourceI x = fmap Identity . runSource x++-- | Run an `XStep` to completion.+runXStep :: (IsoXRec (RSource a m) b, Applicative m) => XStep m a b -> a -> m (Record b)+runXStep x y = rtraverse (`runSourceI` y) (fromXRec x)++-- | The special case where the environnent is a XStep environment is `Record`, and the result should be prepended extensibly.+prependXStep :: (IsoXRec (RSource' a m) b, Applicative m) => XStep' m a b -> Record a -> m (Record (b ++ a))+prependXStep f x = (<+> x) <$> runXStep f x