Copyright | (C) 2017 Csongor Kiss |
---|---|
License | BSD3 |
Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Magic record operations using Generics
These classes need not be instantiated manually, as GHC can automatically
prove valid instances via Generics. Only the Generic
class needs to
be derived (see examples).
Subtype relationship
class Subtype sub sup where Source #
Structural subtype relationship
sub
is a (structural) subtype
of sup
, if its fields are a subset of
those of sup
.
subtype :: forall sup sub. Subtype sub sup => Lens' sub sup Source #
Structural subtype lens. Given a subtype relationship sub :< sup
,
we can focus on the sub
structure of sup
.
>>>
human ^. subtype @Animal
Animal {name = "Tunyasz", age = 50}
>>>
set (subtype @Animal) (Animal "dog" 10) human
Human {name = "dog", age = 10, address = "London"}
Magic lens
class HasField field a s | s field -> a where Source #
Records that have a field with a given name.
Lens focusing on a field with a given name. Compatible with the lens package.
type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s
>>>
human & label @"name" .~ "Tamas"
Human {name = "Tamas", age = 50, address = "London"}