kure-2.18.6: Combinators for Strategic Programming
Copyright(c) 2012--2021 The University of Kansas
LicenseBSD3
MaintainerNeil Sculthorpe <neil.sculthorpe@ntu.ac.uk>
Stabilitybeta
Portabilityghc
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.KURE.Lens

Contents

Description

This module defines the KURE Lens type, along with some useful operations.

Synopsis

Lenses

data Lens c m a b Source #

A Lens is a way to focus on a sub-structure of type b from a structure of type a.

Instances

Instances details
Monad m => Category (Lens c m :: Type -> Type -> Type) Source # 
Instance details

Defined in Language.KURE.Lens

Methods

id :: forall (a :: k). Lens c m a a #

(.) :: forall (b :: k) (c0 :: k) (a :: k). Lens c m b c0 -> Lens c m a b -> Lens c m a c0 #

lens :: Transform c m a ((c, b), b -> m a) -> Lens c m a b Source #

The primitive way of building a Lens. If the unfocussing function is applied to the value focussed on then it should succeed, and produce the same value as the original argument (of type a).

lensT :: Lens c m a b -> Transform c m a ((c, b), b -> m a) Source #

Convert a Lens into a Transform that produces a sub-structure (and its context) and an unfocussing function.

focusR :: Monad m => Lens c m a b -> Rewrite c m b -> Rewrite c m a Source #

Apply a rewrite at a point specified by a Lens.

focusT :: Monad m => Lens c m a b -> Transform c m b d -> Transform c m a d Source #

Apply a transformation at a point specified by a Lens.

pureL :: Monad m => (a -> b) -> (b -> a) -> Lens c m a b Source #

Construct a Lens from two pure functions.

failL :: MonadFail m => String -> Lens c m a b Source #

The failing Lens.

catchL :: MonadCatch m => Lens c m a b -> (String -> Lens c m a b) -> Lens c m a b Source #

A Lens is deemed to have failed (and thus can be caught) if either it fails on the way down, or, crucially, if it would fail on the way up for an unmodified value. However, actual failure on the way up is not caught (as by then it is too late to use an alternative Lens). This means that, in theory, a use of catchL could cause a succeeding Lens application to fail. But provided lens is used correctly, this should never happen.

testLensT :: MonadCatch m => Lens c m a b -> Transform c m a Bool Source #

Check if the focusing succeeds, and additionally whether unfocussing from an unchanged value would succeed.

bidirectionalL :: Monad m => BiTransform c m a b -> Lens c m a b Source #

Construct a Lens from a BiTransform.

injectL :: (MonadFail m, Injection a g) => Lens c m a g Source #

A Lens to the injection of a value.

projectL :: (MonadFail m, Injection a g) => Lens c m g a Source #

A Lens to the projection of a value.