on master help sign in
Get generic prism closer
d539770Matthew Pickering
generic-lens.cabal+1−1
@@ -90,7 +90,7 @@ test-suite generic-lens-test
90 , HUnit
90 , HUnit
91
91
92 default-language: Haskell2010
92 default-language: Haskell2010
93− ghc-options: -Wall -O2 -dsuppress-all
93+ ghc-options: -Wall -O2
94 if flag(dump-core)
94 if flag(dump-core)
95 build-depends: dump-core
95 build-depends: dump-core
96 ghc-options: -fplugin=DumpCore -fplugin-opt DumpCore:core-html
96 ghc-options: -fplugin=DumpCore -fplugin-opt DumpCore:core-html
src/Data/Generics/Sum/Subtype.hs+3−2
@@ -89,7 +89,7 @@ class AsSubtype sub sup where
89 -- >>> duck ^? _Sub :: Maybe FourLeggedAnimal
89 -- >>> duck ^? _Sub :: Maybe FourLeggedAnimal
90 -- Nothing
90 -- Nothing
91 _Sub :: Prism' sup sub
91 _Sub :: Prism' sup sub
92− _Sub eta = prism injectSub projectSub eta
92+ _Sub = prism injectSub projectSub
93 {-# INLINE _Sub #-}
93 {-# INLINE _Sub #-}
94
94
95 -- |Injects a subtype into a supertype (upcast).
95 -- |Injects a subtype into a supertype (upcast).
@@ -108,7 +108,8 @@ instance
108 , GAsSubtype (Rep sub) (Rep sup)
108 , GAsSubtype (Rep sub) (Rep sup)
109 ) => AsSubtype sub sup where
109 ) => AsSubtype sub sup where
110
110
111− _Sub f = prismRavel (prismPRavel (repIso . _GSub . fromIso repIso)) f
111+ _Sub f = prismRavel (repIso . _GSub . fromIso repIso) f
112+ {-# INLINE _Sub #-}
112
113
113-- See Note [Uncluttering type signatures]
114-- See Note [Uncluttering type signatures]
114instance {-# OVERLAPPING #-} AsSubtype a Void where
115instance {-# OVERLAPPING #-} AsSubtype a Void where
test/Spec.hs+2−3
@@ -1,5 +1,5 @@
1{-# OPTIONS_GHC -O -fplugin Test.Inspection.Plugin #-}
1{-# OPTIONS_GHC -O -fplugin Test.Inspection.Plugin #-}
2−{-# OPTIONS_GHC -dsuppress-all #-}
2+{-# OPTIONS_GHC -dsuppress-unfoldings #-}
3
3
4{-# LANGUAGE AllowAmbiguousTypes #-}
4{-# LANGUAGE AllowAmbiguousTypes #-}
5{-# LANGUAGE DataKinds #-}
5{-# LANGUAGE DataKinds #-}
@@ -102,8 +102,7 @@ subtypePrismManual eta = prism g f eta
102 f s1 = case s1 of
102 f s1 = case s1 of
103 A c -> Right (A2 c)
103 A c -> Right (A2 c)
104 B i -> Right (B2 i)
104 B i -> Right (B2 i)
105− C _ -> Left s1
106− D _ -> Left s1
105+ _ -> Left s1
107 g (A2 c) = A c
106 g (A2 c) = A c
108 g (B2 i) = B i
107 g (B2 i) = B i
109
108