Copyright | (C) 2019 Csongor Kiss |
---|---|
License | BSD3 |
Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
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
- 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 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 #
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).
constructorPrism :: Prism s t a b Source #
Instances
AsConstructor' name s a => Constructor (name :: Symbol) s s a a Source # | |
Defined in Data.Generics.Labels constructorPrism :: Prism s s a a Source # | |
AsConstructor name s t a b => Constructor (name :: Symbol) s t a b Source # | |
Defined in Data.Generics.Labels constructorPrism :: Prism s t a b Source # |
type Constructor' name s a = Constructor name s s a a Source #