@@ -111,19 +111,28 @@ class HasField (field :: Symbol) s t a b | s field -> a, t field -> b, s field b
112 field :: VL.Lens s t a b
112 field :: VL.Lens s t a b
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
117-- >>> getField @"age" human
118-- >>> getField @"age" human
119getField :: forall f a s. HasField' f s a => s -> a
120getField :: forall f a s. HasField' f s a => s -> a
120−getField = VL.view (field @f)
121+getField = VL.view (field' @f)
123-- >>> setField @"age" 60 human
124-- >>> setField @"age" 60 human
124-- Human {name = "Tunyasz", age = 60, address = "London", other = False}
125-- Human {name = "Tunyasz", age = 60, address = "London", other = False}
125setField :: forall f s a. HasField' f s a => a -> s -> s
126setField :: forall f s a. HasField' f s a => a -> s -> s
126−setField = VL.set (field @f)
127+setField = VL.set (field' @f)
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' #-}
128instance -- see Note [Changing type parameters]
137instance -- see Note [Changing type parameters]
129 ( Generic s
138 ( Generic s
@@ -145,8 +154,8 @@ instance -- see Note [Changing type parameters]
145 , t ~ Infer s a' b
154 , t ~ Infer s a' b
146 , s ~ Infer t b' a
155 , s ~ Infer t b' a
147 ) => HasField field s t a b where
156 ) => HasField field s t a b where
149 field f s = VL.ravel (repLens . gkey @field) f s
157 field f s = VL.ravel (repLens . gkey @field) f s
158+ {-# INLINE field #-}
151-- -- See Note [Uncluttering type signatures]
160-- -- See Note [Uncluttering type signatures]
152instance {-# OVERLAPPING #-} HasField f (Void1 a) (Void1 b) a b where
161instance {-# OVERLAPPING #-} HasField f (Void1 a) (Void1 b) a b where