class HasField (field :: Symbol) s t a b | s field -> a, t field -> b, s field b -> t, t field a -> s whereRecords that have a field with a given name.
Methods
field :: Lens s t a bA lens that focuses on a field with a given name. Compatible with the lens package's
Control.Lens.Lenstype.Example1 expression human ^. field @"age"50
Type changing
Example1 expression :t humanhuman :: Human Bool
Example1 expression :t human & field @"other" .~ (42 :: Int)human & field @"other" .~ (42 :: Int) :: Human Int
Example1 expression human & field @"other" .~ 42Human {name = "Tunyasz", age = 50, address = "London", other = 42}
Type errors
Example1 expression human & field @"weight" .~ 42...... The type Human Bool does not contain a field named 'weight'....
Example1 expression human & field @"address" .~ ""...... Not all constructors of the type Human Bool... contain a field named 'address'.... The offending constructors are:... HumanNoAddress...
Instances2HasField
(Context field s t a b, HasField0 field s t a b) => HasField field s t a bDefined in generic-lens-2.2.2.0 · Data.Generics.Product.FieldsHasField f (Void1 a) (Void1 b) a bDefined in generic-lens-2.2.2.0 · Data.Generics.Product.FieldsUncluttering type signatures (see Void)
Example1 expression :t +d fieldfield :: (HasField field s t a b, Functor f) => (a -> f b) -> s -> f t