@@ -43,7 +43,7 @@ import Data.Generics.Internal.Families
4343import Data.Generics.Product.Internal.Positions
4444
4545import Data.Kind (Constraint, Type)
46−import Data.Type.Bool (type (&&))
46+import Data.Type.Bool (type (&&), If)
4747import GHC.Generics
4848import GHC.TypeLits (type (<=?), Nat, TypeError, ErrorMessage(..))
4949
@@ -70,7 +70,7 @@ import GHC.TypeLits (type (<=?), Nat, TypeError, ErrorMessage(..))
7070-- :}
7171
7272-- |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
7474 -- |A lens that focuses on a field at a given position. Compatible with the
7575 -- lens package's 'Control.Lens.Lens' type.
7676 --
@@ -100,16 +100,21 @@ instance -- see Note [Changing type parameters]
100100 , ErrorUnless i s (0 <? i && i <=? Size (Rep s))
101101 , Generic t
102102 , s' ~ Proxied s
103+ , t' ~ Proxied t
104+ , Generic s'
105+ , Generic t'
103106 , GHasPosition' i (Rep s) a
104107 , GHasPosition' i (Rep s') a'
108+ , GHasPosition' i (Rep t') b'
105109 , 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
107112 ) => HasPosition i s t a b where
108113
109114 position f s = ravel (repLens . gposition @1 @i) f s
110115
111116-- 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
113118 position = undefined
114119
115120type family ErrorUnless (i :: Nat) (s :: Type) (hasP :: Bool) :: Constraint where