git.iko.soy/semi-iso-optics
on master help sign in
Rename Barter -> Retail. It fits better.
commit40ee1daca64dda7c67cdc90db3164cf5eaa1e644 authorPaweł Nowak <pawel834@gmail.com> dateThu 30 Oct 2014, 16:20 (12 years ago) parentf84672d
2 files changed+41−37
Control/Lens/Internal/SemiIso.hs+33−33 Control/Lens/SemiIso.hs+8−4
Control/Lens/Internal/SemiIso.hs+33−33
@@ -18,52 +18,52 @@ import Data.Profunctor.Exposed
1818-- | Type used internally to access 'SemiIso'.
1919--
2020-- Continues the naming tradition of @lens@.
21−data Barter s t a b = Barter (a -> Either String s) (t -> Either String b)
21+data Retail s t a b = Retail (a -> Either String s) (t -> Either String b)
2222
23−instance Profunctor (Barter s t) where
24− lmap f (Barter l r) = Barter (l . f) r
25− rmap f (Barter l r) = Barter l (fmap f . r)
23+instance Profunctor (Retail s t) where
24+ lmap f (Retail l r) = Retail (l . f) r
25+ rmap f (Retail l r) = Retail l (fmap f . r)
2626
27−instance Choice (Barter s t) where
28− left' (Barter as st) = Barter
29− (either as (\_ -> Left "partial iso failed")) (fmap Left . st)
30− right' (Barter as st) = Barter
31− (either (\_ -> Left "partial iso failed") as) (fmap Right . st)
27+instance Choice (Retail s t) where
28+ left' (Retail as st) = Retail
29+ (either as (\_ -> Left "semi-iso failed")) (fmap Left . st)
30+ right' (Retail as st) = Retail
31+ (either (\_ -> Left "semi-iso failed") as) (fmap Right . st)
3232
3333-- Proof of 'Exposed' laws:
3434--
3535-- > merge . rmap return = id
3636--
37−-- merge . rmap return $ Barter l r =
38−-- merge $ Barter l (return . r) =
39−-- Barter l (join . return . r) =
40−-- Barter l r
37+-- merge . rmap return $ Retail l r =
38+-- merge $ Retail l (return . r) =
39+-- Retail l (join . return . r) =
40+-- Retail l r
4141--
4242-- > lmap return . expose = id
4343--
44−-- lmap return . expose $ Barter l r =
45−-- lmap return $ Barter (>>= l) r =
46−-- Barter ((>>= l) . return) r =
47−-- Barter (join . fmap l . return) r =
48−-- Barter (join . return . l) r =
49−-- Barter l r
44+-- lmap return . expose $ Retail l r =
45+-- lmap return $ Retail (>>= l) r =
46+-- Retail ((>>= l) . return) r =
47+-- Retail (join . fmap l . return) r =
48+-- Retail (join . return . l) r =
49+-- Retail l r
5050--
5151-- > rmap (>>= f) = merge . rmap (fmap f)
5252--
53−-- rmap (>>= f) $ Barter l r =
54−-- Barter l ((>>= f) . r) =
55−-- Barter l (join . fmap f . r) =
56−-- merge $ Barter l (fmap f . r) =
57−-- merge . rmap (fmap f) $ Barter l r
53+-- rmap (>>= f) $ Retail l r =
54+-- Retail l ((>>= f) . r) =
55+-- Retail l (join . fmap f . r) =
56+-- merge $ Retail l (fmap f . r) =
57+-- merge . rmap (fmap f) $ Retail l r
5858--
5959-- > lmap (fmap f) . expose = expose . lmap f
6060--
61−-- lmap (fmap f) . expose $ Barter l r =
62−-- lmap (fmap f) $ Barter (>>= l) r =
63−-- Barter ((>>= l) . fmap f) r =
64−-- Barter (>>= (l . f)) r =
65−-- expose $ Barter (l . f) r =
66−-- expose . lmap f $ Barter l r
67−instance Exposed (Either String) (Barter s t) where
68− expose (Barter l r) = Barter (>>= l) r
69− merge (Barter l r) = Barter l (join . r)
61+-- lmap (fmap f) . expose $ Retail l r =
62+-- lmap (fmap f) $ Retail (>>= l) r =
63+-- Retail ((>>= l) . fmap f) r =
64+-- Retail (>>= (l . f)) r =
65+-- expose $ Retail (l . f) r =
66+-- expose . lmap f $ Retail l r
67+instance Exposed (Either String) (Retail s t) where
68+ expose (Retail l r) = Retail (>>= l) r
69+ merge (Retail l r) = Retail l (join . r)
Control/Lens/SemiIso.hs+8−4
@@ -68,7 +68,11 @@ module Control.Lens.SemiIso (
6868 bifoldr,
6969 bifoldr1,
7070 bifoldl,
71− bifoldl1
71+ bifoldl1,
72+
73+ -- * Profunctor.
74+ Profunctor(..),
75+ Exposed(..)
7276 ) where
7377
7478import Control.Lens.Internal.SemiIso
@@ -93,7 +97,7 @@ type SemiIso s t a b = forall p f. (Exposed (Either String) p, Traversable f) =>
9397type SemiIso' s a = SemiIso s s a a
9498
9599-- | When you see this as an argument to a function, it expects a 'SemiIso'.
96−type ASemiIso s t a b = Barter a b a (Identity b) -> Barter a b s (Identity t)
100+type ASemiIso s t a b = Retail a b a (Identity b) -> Retail a b s (Identity t)
97101
98102-- | When you see this as an argument to a function, it expects a 'SemiIso''.
99103type ASemiIso' s a = ASemiIso s s a a
@@ -107,8 +111,8 @@ semiIso sa bt = merge . dimap sa (sequenceA . fmap bt) . expose
107111withSemiIso :: ASemiIso s t a b
108112 -> ((s -> Either String a) -> (b -> Either String t) -> r)
109113 -> r
110−withSemiIso ai k = case ai (Barter Right (Right . Identity)) of
111− Barter sa bt -> k sa (rmap (runIdentity . sequenceA) bt)
114+withSemiIso ai k = case ai (Retail Right (Right . Identity)) of
115+ Retail sa bt -> k sa (rmap (runIdentity . sequenceA) bt)
112116
113117-- | Applies the 'SemiIso'.
114118apply :: ASemiIso s t a b -> s -> Either String a