@@ -111,19 +111,28 @@ class HasField (field :: Symbol) s t a b | s field -> a, t field -> b, s field b
111111 -- ...
112112 field :: VL.Lens s t a b
113113
114−type HasField' field s a = HasField field s s a a
114+class HasField' (field :: Symbol) s a | s field -> a where
115+ field' :: VL.Lens s s a a
115116
116117-- |
117118-- >>> getField @"age" human
118119-- 50
119120getField :: forall f a s. HasField' f s a => s -> a
120−getField = VL.view (field @f)
121+getField = VL.view (field' @f)
121122
122123-- |
123124-- >>> setField @"age" 60 human
124125-- Human {name = "Tunyasz", age = 60, address = "London", other = False}
125126setField :: forall f s a. HasField' f s a => a -> s -> s
126−setField = VL.set (field @f)
127+setField = VL.set (field' @f)
128+
129+instance
130+ ( Generic s
131+ , ErrorUnless field s (CollectField field (Rep s))
132+ , GHasKey' field (Rep s) a
133+ ) => HasField' field s a where
134+ field' f s = VL.ravel (repLens . gkey @field) f s
135+ {-# INLINE field' #-}
127136
128137instance -- see Note [Changing type parameters]
129138 ( Generic s
@@ -145,8 +154,8 @@ instance -- see Note [Changing type parameters]
145154 , t ~ Infer s a' b
146155 , s ~ Infer t b' a
147156 ) => HasField field s t a b where
148−
149157 field f s = VL.ravel (repLens . gkey @field) f s
158+ {-# INLINE field #-}
150159
151160-- -- See Note [Uncluttering type signatures]
152161instance {-# OVERLAPPING #-} HasField f (Void1 a) (Void1 b) a b where