packages feed

fclabels 2.0 → 2.0.0.1

raw patch · 4 files changed

+50/−36 lines, 4 files

Files

fclabels.cabal view
@@ -1,5 +1,5 @@ Name:          fclabels-Version:       2.0+Version:       2.0.0.1 Author:        Sebastiaan Visser, Erik Hesselink, Chris Eidhof, Sjoerd Visscher                with lots of help and feedback from others. Synopsis:      First class accessor labels implemented as lenses.@@ -47,30 +47,9 @@                See "Data.Label.Base" and "Data.Label.Monadic" for more                information.                .-               * /Changelog from 1.1.7.1 to 2.0/+               * /Changelog from 2.0 to 2.0.0.1/                .-               >   - Introduced polymorphic lenses.-               >   - Lenses are now based on getters and modifiers, not getters and setters.-               >   - Pure lenses are now named Total lenses.-               >   - Maybe lenses are now named Partial lenses.-               >   - Introduced Failing lenses that preserve errors.-               >   - Generalized Point data type.-               >   - Removed unused monadic functions for partial lenses.-               >   - Added ArrowFail type class.-               >   - Added lenses for base types. (tuples, lists, Maybe, Either)-               >   - Isomorphisms now uses regular function space for base morphism.-               >   - Swapped iso for more useful inv.-               >   - Introduced iso to more easily lift isomorphisms into lenses.-               >   - Removed mainly unused bimap.-               >   - Added derivation of lenses as expressions.-               >   - Convert record declarations directly into fclabels variants.-               >   - Allow deriving lenses for GADTs.-               >   - Added reasonably sophisticated totality checker for GADT labels.-               >   - Derived lenses can now fail in either ArrowZero or ArrowFail.-               >   - Alternative instance for Point.-               >   - Vertical composition for multi-constructor data types.-               >   - Extensive test suite.-               >   - Fully documented.+               >   - Remove warnings on generated labels with OverloadedStrings.  Maintainer:    Sebastiaan Visser <code@fvisser.nl> Homepage:      https://github.com/sebastiaanvisser/fclabels
src/Data/Label/Derive.hs view
@@ -363,8 +363,8 @@          failE   = if failing                    then [| failArrow |]                    else [| zeroArrow |]-         getT    = [| arr $(getter total field) |]-         putT    = [| arr $(setter total field) |]+         getT    = [| arr $(getter failing total field) |]+         putT    = [| arr $(setter failing total field) |]          getP    = [| $(failE) ||| id <<< $getT |]          putP    = [| $(failE) ||| id <<< $putT |]          failP   = if failing@@ -421,10 +421,10 @@  ------------------------------------------------------------------------------- -getter :: Bool -> Field ([Context], Subst) -> Q Exp-getter total (Field mn _ _ (cons, _)) =+getter :: Bool -> Bool -> Field ([Context], Subst) -> Q Exp+getter failing total (Field mn _ _ (cons, _)) =   do let pt = mkName "f"-         nm = maybe (tupE []) (litE . StringL . nameBase) mn+         nm = maybe (tupE []) (litE . StringL . nameBase) (guard failing >> mn)          wild = if total then [] else [match wildP (normalB [| Left $(nm) |]) []]          rght = if total then id else appE [| Right |]          mkCase (Context i _ c) = match pat (normalB (rght var)) []@@ -443,11 +443,11 @@           pats  = replicate i wildP ++ [pats1 !! i] ++ repeat wildP           var   = varE (fresh !! i) -setter :: Bool -> Field ([Context], Subst) -> Q Exp-setter total (Field mn _ _ (cons, _)) =+setter :: Bool -> Bool -> Field ([Context], Subst) -> Q Exp+setter failing total (Field mn _ _ (cons, _)) =   do let pt = mkName "f"          md = mkName "v"-         nm = maybe (tupE []) (litE . StringL . nameBase) mn+         nm = maybe (tupE []) (litE . StringL . nameBase) (guard failing >> mn)          wild = if total then [] else [match wildP (normalB [| Left $(nm) |]) []]          rght = if total then id else appE [| Right |]          mkCase (Context i _ c) = match pat (normalB (rght var)) []
src/Data/Label/Partial.hs view
@@ -17,6 +17,9 @@ -- * Seemingly total modifications. , set' , modify'++-- * Potentially removing modification.+, update ) where @@ -89,4 +92,10 @@  set' :: (f -> f) :~> (o -> o) -> o -> f -> f set' l v f = f `fromMaybe` set l v f++-- | Like `modify`, but update allows, depending on the underlying lens, to+-- remove items by modifying to `Nothing`.++update :: (f -> b) :~> (o -> i) -> (o -> Maybe i) -> f -> Maybe b+update l m = runKleisli (Poly.modify l . arr ((,) (Kleisli m))) 
src/Data/Label/Total.hs view
@@ -1,7 +1,7 @@-{-| Default lenses for simple total getters and monomorphic updates. Useful for-creating accessor labels for single constructor datatypes. Also useful field-labels that are shared between all the constructors of a multi constructor-datatypes.+{-| Default lenses for simple total getters and total possibly polymorphic,+updates. Useful for creating accessor labels for single constructor datatypes.+Also useful field labels that are shared between all the constructors of a+multi constructor datatypes. -}  {-# LANGUAGE TypeOperators #-}@@ -13,9 +13,14 @@ , get , modify , set++-- * Working in contexts.+, traverse+, lifted ) where +import Control.Monad ((<=<), liftM) import Data.Label.Poly (Lens) import Data.Label.Point (Total) @@ -59,4 +64,25 @@  set :: ((f -> g) :-> (o -> i)) -> i -> f -> g set = curry . Poly.set++-- | Modify in some context.++traverse :: Functor m => (f -> g) :-> (o -> i) -> (o -> m i) -> f -> m g+traverse l m f = (\w -> set l w f) `fmap` m (get l f)+++-- | Lifted lens composition.+--+-- For example, useful when specialized to lists:+--+-- > :: (f :-> [o])+-- > -> (o :-> [a])+-- > -> (f :-> [a])++lifted+  :: Monad m+  => (f -> g) :-> (m o -> m i)+  -> (o -> i) :-> (m a -> m b)+  -> (f -> g) :-> (m a -> m b)+lifted a b = lens (get b <=< get a) (modify a . liftM . modify b)