generic-lens-0.4.0.1: Generic data-structure operations exposed as lenses.

Copyright(C) 2017 Csongor Kiss
LicenseBSD3
MaintainerCsongor Kiss <kiss.csongor.kiss@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Data.Generics.Product.Subtype

Contents

Description

Structural subtype relationships between product types.

Synopsis

Lenses

class Subtype sup sub where #

Structural subtype relationship

sub is a (structural) subtype of sup, if its fields are a subset of those of sup.

Minimal complete definition

super | smash, upcast

Methods

super :: Lens' sub sup #

Structural subtype lens. Given a subtype relationship sub :< sup, we can focus on the sub structure of sup.

>>> human ^. super @Animal
Animal {name = "Tunyasz", age = 50}
>>> set (super @Animal) (Animal "dog" 10) human
Human {name = "dog", age = 10, address = "London"}

upcast :: sub -> sup #

Cast the more specific subtype to the more general supertype

>>> upcast human :: Animal
Animal {name = "Tunyasz", age = 50}

smash :: sup -> sub -> sub #

Plug a smaller structure into a larger one

>>> smash (Animal "dog" 10) human
Human {name = "dog", age = 10, address = "London"}

Instances

(GSmash * (Rep a) (Rep b), GUpcast (Rep a) (Rep b), Generic a, Generic b) => Subtype b a # 

Methods

super :: Lens' a b #

upcast :: a -> b #

smash :: b -> a -> a #