generic-lens-1.2.0.1: Generically derive traversals, lenses and prisms.

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

Data.Generics.Labels

Contents

Description

Provides an (orphan) IsLabel instance for field lenses and constructor prisms. Use at your own risk.

Synopsis

Orphan IsLabel Instance

An instance for creating lenses and prisms with #identifiers from the OverloadedLabels extension. Note that since overloaded labels do not support symbols starting with capital letters, all prisms (which come from constructor names, which are capitalized) must be prefixed with an underscore (e.g. #_ConstructorName).

Morally:

instance (HasField name s t a b) => IsLabel name (Lens s t a b) where ...

and

instance (AsConstructor name s t a b) => IsLabel name (Prism s t a b) where ...

Remember:

type Lens = forall f. Functor f => (a -> f b) -> s -> f t

type Prism s t a b = forall p f. (Choice p, Applicative f) => p a (f b) -> p s (f t)

The orphan instance is unavoidable if we want to work with lenses-as-functions (as opposed to a ReifiedLens-like newtype).

class Field name s t a b | s name -> a, t name -> b, s name b -> t, t name a -> s where Source #

Field is morally the same as HasField, but it is constructed from an incoherent combination of HasField and HasField'. In this way, it can be seamlessly used in the IsLabel instance even when dealing with data types that don't have Field instances (like data instances).

Methods

fieldLens :: Lens s t a b Source #

Instances
HasField' name s a => Field (name :: Symbol) s s a a Source # 
Instance details

Defined in Data.Generics.Labels

Methods

fieldLens :: Lens s s a a Source #

HasField name s t a b => Field (name :: Symbol) s t a b Source # 
Instance details

Defined in Data.Generics.Labels

Methods

fieldLens :: Lens s t a b Source #

type Field' name s a = Field name s s a a Source #

class Constructor name s t a b | name s -> a, name t -> b where Source #

Constructor is morally the same as AsConstructor, but it is constructed from an incoherent combination of AsConstructor and AsConstructor'. In this way, it can be seamlessly used in the IsLabel instance even when dealing with data types that don't have Constructor instances (like data instances).

Methods

constructorPrism :: Prism s t a b Source #

Instances
AsConstructor' name s a => Constructor (name :: Symbol) s s a a Source # 
Instance details

Defined in Data.Generics.Labels

Methods

constructorPrism :: Prism s s a a Source #

AsConstructor name s t a b => Constructor (name :: Symbol) s t a b Source # 
Instance details

Defined in Data.Generics.Labels

Methods

constructorPrism :: Prism s t a b Source #

type Constructor' name s a = Constructor name s s a a Source #

Orphan instances

(capital ~ BeginsWithCapital name, IsLabelHelper capital name p f s t a b, pafb ~ p a (f b), psft ~ p s (f t)) => IsLabel name (pafb -> psft) Source # 
Instance details

Methods

fromLabel :: pafb -> psft #