@@ -43,7 +43,7 @@ import Data.Generics.Internal.Families
43import Data.Generics.Product.Internal.Positions
43import Data.Generics.Product.Internal.Positions
45import Data.Kind (Constraint, Type)
45import Data.Kind (Constraint, Type)
46−import Data.Type.Bool (type (&&))
46+import Data.Type.Bool (type (&&), If)
47import GHC.Generics
47import GHC.Generics
48import GHC.TypeLits (type (<=?), Nat, TypeError, ErrorMessage(..))
48import GHC.TypeLits (type (<=?), Nat, TypeError, ErrorMessage(..))
@@ -70,7 +70,7 @@ import GHC.TypeLits (type (<=?), Nat, TypeError, ErrorMessage(..))
72-- |Records that have a field at a given position.
72-- |Records that have a field at a given position.
73−class HasPosition (i :: Nat) s t a b | s i -> a, s i b -> t where
73+class HasPosition (i :: Nat) s t a b | s i -> a, s i b -> t, t i a -> s where
74 -- |A lens that focuses on a field at a given position. Compatible with the
74 -- |A lens that focuses on a field at a given position. Compatible with the
75 -- lens package's 'Control.Lens.Lens' type.
75 -- lens package's 'Control.Lens.Lens' type.
@@ -100,16 +100,21 @@ instance -- see Note [Changing type parameters]
100 , ErrorUnless i s (0 <? i && i <=? Size (Rep s))
100 , ErrorUnless i s (0 <? i && i <=? Size (Rep s))
101 , Generic t
101 , Generic t
102 , s' ~ Proxied s
102 , s' ~ Proxied s
103 , GHasPosition' i (Rep s) a
106 , GHasPosition' i (Rep s) a
104 , GHasPosition' i (Rep s') a'
107 , GHasPosition' i (Rep s') a'
108+ , GHasPosition' i (Rep t') b'
105 , GHasPosition 1 i (Rep s) (Rep t) a b
109 , GHasPosition 1 i (Rep s) (Rep t) a b
106− , t ~ Infer s a' b
110+ , t ~ If (HasParams s) (Infer s a' b) s
111+ , s ~ If (HasParams t) (Infer t b' a) t
107 ) => HasPosition i s t a b where
112 ) => HasPosition i s t a b where
109 position f s = ravel (repLens . gposition @1 @i) f s
114 position f s = ravel (repLens . gposition @1 @i) f s
111-- See Note [Uncluttering type signatures]
116-- See Note [Uncluttering type signatures]
112−instance {-# OVERLAPPING #-} HasPosition f (Void2 a t) t a b where
117+instance {-# OVERLAPPING #-} HasPosition f (Void1 a) (Void1 b) a b where
113 position = undefined
118 position = undefined
115type family ErrorUnless (i :: Nat) (s :: Type) (hasP :: Bool) :: Constraint where
120type family ErrorUnless (i :: Nat) (s :: Type) (hasP :: Bool) :: Constraint where