@@ -46,9 +46,6 @@ type Prism s t a b
46type PrismP s t a b
46type PrismP s t a b
47 = forall p . (Choice p) => p a b -> p s t
47 = forall p . (Choice p) => p a b -> p s t
50− = forall p f. (MRight p, MProfunctor p) => p a b -> p s t
52type Prism' s a
49type Prism' s a
53 = Prism s s a a
50 = Prism s s a a
@@ -61,6 +58,9 @@ type Iso s t a b
61type IsoE s t a b
58type IsoE s t a b
62 = forall p f. (MProfunctor p) => p a b -> p s t
59 = forall p f. (MProfunctor p) => p a b -> p s t
62+ = forall p f. (Profunctor p) => p a b -> p s t
64-- | Getting
64-- | Getting
65(^.) :: s -> ((a -> Const a a) -> s -> Const a s) -> a
65(^.) :: s -> ((a -> Const a a) -> s -> Const a s) -> a
66s ^. l = getConst (l Const s)
66s ^. l = getConst (l Const s)
@@ -97,14 +97,14 @@ second f (a :*: b)
97left :: Prism ((a :+: c) x) ((b :+: c) x) (a x) (b x)
97left :: Prism ((a :+: c) x) ((b :+: c) x) (a x) (b x)
98left = prism L1 $ gsum Right (Left . R1)
98left = prism L1 $ gsum Right (Left . R1)
100+leftP :: PrismP ((a :+: c) x) ((b :+: c) x) (a x) (b x)
101+leftP = prismP L1 $ gsum Right (Left . R1)
100right :: Prism ((a :+: b) x) ((a :+: c) x) (b x) (c x)
103right :: Prism ((a :+: b) x) ((a :+: c) x) (b x) (c x)
101right = prism R1 $ gsum (Left . L1) Right
104right = prism R1 $ gsum (Left . L1) Right
103−leftE :: PrismE ((a :+: c) x) ((b :+: c) x) (a x) (b x)
104−leftE = prismE L1 $ gsum Right (Left . R1)
106−rightE :: PrismE ((a :+: b) x) ((a :+: c) x) (b x) (c x)
106+rightP :: PrismP ((a :+: b) x) ((a :+: c) x) (b x) (c x)
107−rightE = prismE R1 $ gsum (Left . L1) Right
107+rightP = prismP R1 $ gsum (Left . L1) Right
109gsum :: (a x -> c) -> (b x -> c) -> ((a :+: b) x) -> c
109gsum :: (a x -> c) -> (b x -> c) -> ((a :+: b) x) -> c
110gsum f _ (L1 x) = f x
110gsum f _ (L1 x) = f x
@@ -114,9 +114,6 @@ combine :: Lens' (s x) a -> Lens' (t x) a -> Lens' ((s :+: t) x) a
114combine sa _ f (L1 s) = fmap (\a -> L1 (set sa a s)) (f (s ^. sa))
114combine sa _ f (L1 s) = fmap (\a -> L1 (set sa a s)) (f (s ^. sa))
115combine _ ta f (R1 t) = fmap (\a -> R1 (set ta a t)) (f (t ^. ta))
115combine _ ta f (R1 t) = fmap (\a -> R1 (set ta a t)) (f (t ^. ta))
117−prismE :: (b -> t) -> (s -> Either t a) -> PrismE s t a b
118−prismE bt seta = mdimap (liftFun seta) (EitherFun id bt) . mright
120prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
117prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
121prism bt seta eta = dimap (\x -> plus pure id (seta x)) (either id (\x -> fmap bt x)) (right' eta)
118prism bt seta eta = dimap (\x -> plus pure id (seta x)) (either id (\x -> fmap bt x)) (right' eta)
122{-# INLINE prism #-}
119{-# INLINE prism #-}
@@ -129,8 +126,9 @@ prismP bt seta eta = dimap seta (either id bt) (right' eta)
129repIso :: (Generic a, Generic b) => Iso a b (Rep a x) (Rep b x)
126repIso :: (Generic a, Generic b) => Iso a b (Rep a x) (Rep b x)
130repIso = dimap from (fmap to)
127repIso = dimap from (fmap to)
129+-- | A type and its generic representation are isomorphic
132−repIsoE :: (Generic a, Generic b) => IsoE a b (Rep a x) (Rep b x)
130+repIsoP :: (Generic a, Generic b) => IsoP a b (Rep a x) (Rep b x)
133−repIsoE = ddimap from to
131+repIsoP = dimap from to
136-- | 'M1' is just a wrapper around `f p`
134-- | 'M1' is just a wrapper around `f p`
@@ -140,8 +138,8 @@ mIso = dimap unM1 (fmap M1)
141-- | 'M1' is just a wrapper around `f p`
139-- | 'M1' is just a wrapper around `f p`
142--mIso :: Iso' (M1 i c f p) (f p)
140--mIso :: Iso' (M1 i c f p) (f p)
143−mIsoE :: IsoE (M1 i c f p) (M1 i c g p) (f p) (g p)
141+mIsoP :: IsoP (M1 i c f p) (M1 i c g p) (f p) (g p)
144−mIsoE = ddimap unM1 M1
142+mIsoP = dimap unM1 M1
146-- These are specialised versions of the Isos above. On GHC 8.0.2, having
144-- These are specialised versions of the Isos above. On GHC 8.0.2, having
147-- these functions eta-expanded allows the optimiser to inline these functions.
145-- these functions eta-expanded allows the optimiser to inline these functions.