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

Copyright | (C) 2020 Csongor Kiss
License | BSD3
Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Generics.Labels

Contents

- Orphan IsLabel Instance
- Orphan instances

Description

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

Synopsis

- class Field name s t a b | s name -> a, t name -> b, s name b -> t, t name a -> s where
  - fieldLens :: Lens s t a b
- type Field' name s a = Field name s s a a
- class Constructor name s t a b | name s -> a, name t -> b where
  - constructorPrism :: Prism s t a b
- type Constructor' name s a = Constructor name s s a a

# Orphan IsLabel Instance

An instance for creating lenses and prisms with `#identifiers` from the `OverloadedLabels` extension. Note that since overloaded labels did 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`) when you use a GHC older than 9.6.

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

Instances details

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

Instances details

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

(labelType ~ ClassifyLabel name, IsLabelHelper labelType 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 Source #