{-# 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 :: forall (cat :: * -> * -> *) f o.
cat f o -> cat (cat o o, f) f -> Lens cat f o
lens = 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 :: forall (cat :: * -> * -> *) f o. Lens cat f o -> cat f o
get = 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 :: forall (cat :: * -> * -> *) f o. Lens cat f o -> cat (cat o o, f) f
modify = 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 :: forall (arr :: * -> * -> *) f o.
Arrow arr =>
Lens arr f o -> arr (o, f) f
set = 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 :: forall (cat :: * -> * -> *) f o. Point cat f o f o -> Lens cat f o
point = 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 :: forall (cat :: * -> * -> *) f o.
ArrowApply cat =>
Iso cat f o -> Lens cat f o
iso (Iso cat f o
f cat o f
b) = forall (cat :: * -> * -> *) f o.
cat f o -> cat (cat o o, f) f -> Lens cat f o
lens cat f o
f (forall (a :: * -> * -> *) b c. ArrowApply a => a (a b c, b) c
app forall {k} (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\(cat o o
m, f
v) -> (cat o f
b 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 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