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.
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-optics-2.2.1.0 · Data.Generics.Product.FieldsHasField f (Void1 a) (Void1 b) a bDefined in generic-optics-2.2.1.0 · Data.Generics.Product.FieldsSee Note [Uncluttering type signatures] >>> :t field field :: HasField field s t a b => Lens s t a b