@@ -9,7 +9,7 @@
99{-# language TypeOperators #-}
1010{-# language UndecidableInstances #-}
1111module Data.Generics.Iso
12− ( Is(..)
12+ ( Wrapped(..)
1313 , _Unwrapped
1414 , _Wrapped
1515 )
@@ -22,25 +22,25 @@ import Data.Kind (Constraint)
2222import GHC.Generics
2323import GHC.TypeLits
2424
25−class GIso a b | a -> b where
26− gIso :: Iso' (a x) b
25+class GWrapped a b | a -> b where
26+ gWrapped :: Iso' (a x) b
2727
28−instance GIso a b => GIso (M1 i k a) b where
29− gIso = mIso.gIso
28+instance GWrapped a b => GWrapped (M1 i k a) b where
29+ gWrapped = mIso.gWrapped
3030
31−instance GIso (K1 i c) c where
32− gIso = kIso
31+instance GWrapped (K1 i c) c where
32+ gWrapped = kIso
3333
34−class Is a b | a -> b where
35− {-# minimal _Is | isTo, isFrom #-}
36− _Is :: VL.Iso' a b
37− _Is = iso isTo isFrom
34+class Wrapped a b | a -> b where
35+ {-# minimal wrappedIso | wrappedTo, wrappedFrom #-}
36+ wrappedIso :: VL.Iso' a b
37+ wrappedIso = iso wrappedTo wrappedFrom
3838
39− isTo :: a -> b
40− isTo a = a ^. _Is
39+ wrappedTo :: a -> b
40+ wrappedTo a = a ^. wrappedIso
4141
42− isFrom :: b -> a
43− isFrom a = a ^. fromIso _Is
42+ wrappedFrom :: b -> a
43+ wrappedFrom a = a ^. fromIso wrappedIso
4444
4545type family ErrorUnlessOnlyOne a b :: Constraint where
4646 ErrorUnlessOnlyOne t (M1 i k a) = ErrorUnlessOnlyOne t a
@@ -48,11 +48,11 @@ type family ErrorUnlessOnlyOne a b :: Constraint where
4848 ErrorUnlessOnlyOne t a =
4949 TypeError ('ShowType t ':<>: 'Text " is not a single-constructor, single-field datatype")
5050
51−instance (Generic a, ErrorUnlessOnlyOne a (Rep a), GIso (Rep a) b) => Is a b where
52− _Is = repIso . gIso
51+instance (Generic a, ErrorUnlessOnlyOne a (Rep a), GWrapped (Rep a) b) => Wrapped a b where
52+ wrappedIso = repIso . gWrapped
5353
54−_Unwrapped :: Is a b => Iso' a b
55−_Unwrapped = _Is
54+_Unwrapped :: Wrapped a b => Iso' a b
55+_Unwrapped = wrappedIso
5656
57−_Wrapped :: Is a b => Iso' b a
58−_Wrapped = fromIso _Is
57+_Wrapped :: Wrapped a b => Iso' b a
58+_Wrapped = fromIso wrappedIso