optics-vl (empty) → 0.1
raw patch · 4 files changed
+169/−0 lines, 4 filesdep +basedep +optics-coredep +profunctorssetup-changed
Dependencies added: base, optics-core, profunctors
Files
- LICENSE +30/−0
- Setup.hs +4/−0
- optics-vl.cabal +33/−0
- src/Optics/VL.hs +102/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2017-2019, Well-Typed LLP++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 Well-Typed LLP 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.
+ Setup.hs view
@@ -0,0 +1,4 @@+import Distribution.Simple++main :: IO ()+main = defaultMain
+ optics-vl.cabal view
@@ -0,0 +1,33 @@+name: optics-vl+version: 0.1+license: BSD3+license-file: LICENSE+build-type: Simple+maintainer: optics@well-typed.com+author: Andrzej Rybczak+cabal-version: >=1.10+tested-with: ghc ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1+synopsis: Utilities for compatibility with van Laarhoven optics+category: Data, Optics, Lenses+description:+ This package is part of the @optics@ package family. It provides utilities+ for converting between the 'Optic' type defined by @optics@ and the van+ Laarhoven representations of optics (in particular isomorphisms and prisms).++bug-reports: https://github.com/well-typed/optics/issues+source-repository head+ type: git+ location: https://github.com/well-typed/optics.git+ subdir: optics-vl++library+ default-language: Haskell2010+ hs-source-dirs: src++ build-depends: base >= 4.9 && <5+ , optics-core >= 0.1 && <1+ , profunctors >= 5.0 && <6.0++ ghc-options: -Wall++ exposed-modules: Optics.VL
+ src/Optics/VL.hs view
@@ -0,0 +1,102 @@+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}+-- |+-- Module: Optics.VL+--+-- This module provides compatibility layer for converting from van Laarhoven+-- encoding of 'Iso's, 'Prism's, 'Lens'es, 'IxLens'es, 'AffineTraversal's,+-- 'IxAffineTraversal's, 'Traversal's and 'IxTraversal's to their optics+-- equivalents.+module Optics.VL+ (+ -- * Iso+ IsoVL+ , IsoVL'+ , isoVL+ -- * Prism+ , PrismVL+ , PrismVL'+ , prismVL+ -- * Lens+ , LensVL+ , LensVL'+ , lensVL+ -- * IxLens+ , IxLensVL+ , IxLensVL'+ , ilensVL+ -- * AffineTraversal+ , AffineTraversalVL+ , AffineTraversalVL'+ , atraversalVL+ -- * IxAffineTraversal+ , IxAffineTraversalVL+ , IxAffineTraversalVL'+ , iatraversalVL+ -- * Traversal+ , TraversalVL+ , TraversalVL'+ , traversalVL+ -- * IxTraversal+ , IxTraversalVL+ , IxTraversalVL'+ , itraversalVL+ ) where++import Data.Functor.Identity+import qualified Data.Profunctor as P++import Optics.Internal.Optic+import Optics.Internal.Profunctor+import Optics.Internal.Utils+import Optics.Core++newtype WrappedProfunctor p i a b =+ WrapProfunctor { unwrapProfunctor :: p i a b }++instance Profunctor p => P.Profunctor (WrappedProfunctor p i) where+ dimap f g (WrapProfunctor pab) = WrapProfunctor (dimap f g pab)+ lmap f (WrapProfunctor pab) = WrapProfunctor (lmap f pab)+ rmap g (WrapProfunctor pab) = WrapProfunctor (rmap g pab)+ {-# INLINE dimap #-}+ {-# INLINE lmap #-}+ {-# INLINE rmap #-}++instance Choice p => P.Choice (WrappedProfunctor p i) where+ left' (WrapProfunctor pab) = WrapProfunctor (left' pab)+ right' (WrapProfunctor pab) = WrapProfunctor (right' pab)+ {-# INLINE left' #-}+ {-# INLINE right' #-}++----------------------------------------++-- | Type synonym for a type-modifying van Laarhoven iso.+type IsoVL s t a b =+ forall p f. (P.Profunctor p, Functor f) => p a (f b) -> p s (f t)++-- | Type synonym for a type-preserving van Laarhoven iso.+type IsoVL' s a = IsoVL s s a a++-- | Build an 'Iso' from the van Laarhoven representation.+isoVL :: forall s t a b. IsoVL s t a b -> Iso s t a b+isoVL f = Optic $ rcoerce @(Identity t) @t+ . (unwrapProfunctor #. f .# WrapProfunctor)+ . rcoerce @b @(Identity b)+{-# INLINE isoVL #-}++----------------------------------------++-- | Type synonym for a type-modifying van Laarhoven prism.+type PrismVL s t a b =+ forall p f. (P.Choice p, Applicative f) => p a (f b) -> p s (f t)++-- | Type synonym for a type-preserving van Laarhoven prism.+type PrismVL' s a = PrismVL s s a a++-- | Build a 'Prism' from the van Laarhoven representation.+prismVL :: forall s t a b. PrismVL s t a b -> Prism s t a b+prismVL f = Optic $ rcoerce @(Identity t) @t+ . (unwrapProfunctor #. f .# WrapProfunctor)+ . rcoerce @b @(Identity b)+{-# INLINE prismVL #-}