{-# LANGUAGE
FlexibleInstances
, MultiParamTypeClasses
, TypeOperators
#-}
module Data.Label.Mono
( Lens
, lens
, get
, modify
, point
, set
, iso
, (:->)
, (:~>)
)
where
import Control.Category
import Control.Arrow
import Data.Label.Point (Point, Iso (..), Total, Partial)
import Prelude ()
import qualified Data.Label.Poly as Poly
{-# INLINE lens #-}
{-# INLINE get #-}
{-# INLINE modify #-}
{-# INLINE set #-}
{-# INLINE point #-}
{-# INLINE iso #-}
type Lens cat f o = Poly.Lens cat (f -> f) (o -> o)
lens :: cat f o
-> (cat (cat o o, f) f)
-> Lens cat f o
lens :: cat f o -> cat (cat o o, f) f -> Lens cat f o
lens = cat f o -> cat (cat o o, f) f -> Lens cat f o
forall (cat :: * -> * -> *) f o i g.
cat f o -> cat (cat o i, f) g -> Lens cat (f -> g) (o -> i)
Poly.lens
get :: Lens cat f o -> cat f o
get :: Lens cat f o -> cat f o
get = Lens cat f o -> cat f o
forall (cat :: * -> * -> *) f g o i.
Lens cat (f -> g) (o -> i) -> cat f o
Poly.get
modify :: Lens cat f o -> cat (cat o o, f) f
modify :: Lens cat f o -> cat (cat o o, f) f
modify = Lens cat f o -> cat (cat o o, f) f
forall (cat :: * -> * -> *) f g o i.
Lens cat (f -> g) (o -> i) -> cat (cat o i, f) g
Poly.modify
set :: Arrow arr => Lens arr f o -> arr (o, f) f
set :: Lens arr f o -> arr (o, f) f
set = Lens arr f o -> arr (o, f) f
forall (arr :: * -> * -> *) f g o i.
Arrow arr =>
Lens arr (f -> g) (o -> i) -> arr (i, f) g
Poly.set
point :: Point cat f o f o -> Lens cat f o
point :: Point cat f o f o -> Lens cat f o
point = Point cat f o f o -> Lens cat f o
forall (cat :: * -> * -> *) g i f o.
Point cat g i f o -> Lens cat (f -> g) (o -> i)
Poly.point
iso :: ArrowApply cat => Iso cat f o -> Lens cat f o
iso :: Iso cat f o -> Lens cat f o
iso (Iso cat f o
f cat o f
b) = cat f o -> cat (cat o o, f) f -> Lens cat f o
forall (cat :: * -> * -> *) f o.
cat f o -> cat (cat o o, f) f -> Lens cat f o
lens cat f o
f (cat (cat f f, f) f
forall (a :: * -> * -> *) b c. ArrowApply a => a (a b c, b) c
app cat (cat f f, f) f
-> cat (cat o o, f) (cat f f, f) -> cat (cat o o, f) f
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ((cat o o, f) -> (cat f f, f)) -> cat (cat o o, f) (cat f f, f)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\(cat o o
m, f
v) -> (cat o f
b cat o f -> cat f o -> cat f f
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. cat o o
m cat o o -> cat f o -> cat f o
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. cat f o
f, f
v)))
type f :-> o = Lens Total f o
type f :~> o = Lens Partial f o