Commit c2d3e355 authored by root's avatar root
Browse files

Initial commit, v0.1.0.0

parents
No related merge requests found
Pipeline #82 failed with stages
.stack-work/
*~
\ No newline at end of file
image: nixos/nix:latest
before_script:
- export LC_ALL=C.UTF-8
- nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
- nix-channel --update
- nix-env -iA nixpkgs.stack
- nix-env -iA nixpkgs.hlint
stages:
- lint
- build
hlint:
stage: lint
script:
- hlint .
build:
stage: build
script:
- stack --nix build --ghc-options "-Wall -Werror"
# Changelog for composite-xstep
## (v0.1.0.0)
* Initial commit - Higher kinded ReaderT transformer pattern for composite records.
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.
# 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
```
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
name: composite-xstep
version: 0.1.0.0
git: https://gitlab.com/homotopic-tech/composite-xstep
license: MIT
author: "Daniel Firth"
maintainer: "dan.firth@homotopic.tech"
copyright: "2020 Daniel Firth"
extra-source-files:
- README.md
- ChangeLog.md
synopsis: ReaderT transformer pattern for higher kinded composite data.
category: Data Structures
description: ReaderT transformer pattern for higher kinded composite data.
dependencies:
- base >= 4.7 && < 5
- composite-base
- vinyl
ghc-options:
- -Wall
- -Wcompat
- -Wincomplete-record-updates
- -Wincomplete-uni-patterns
- -Wredundant-constraints
library:
source-dirs: src
{-# 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
resolver: nightly-2020-08-27
packages:
- .
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
snapshots:
- completed:
size: 523649
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/8/27.yaml
sha256: 95012648db1b2180e3d7e0a3d44bc2a61b6854028382674724fee7ffa24300c3
original: nightly-2020-08-27
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment