| 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 | 
Data.Generics.Sum
Contents
Description
Magic sum 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).
- class AsAny sel a s | s sel k -> a where
- class AsConstructor ctor a s | s ctor -> a where
- class AsType a s where
Prisms
class AsAny sel a s | s sel k -> a where Source #
Sums that have generic prisms.
Methods
A prism that projects a sum as identified by some selector. Currently
  supported selectors are constructor names and unique types. Compatible
  with the lens package's Prism type.
>>>dog ^? _As @"Dog"Just (MkDog {name = "Shep", age = 3})>>>dog ^? _As @DogJust (MkDog {name = "Shep", age = 3})>>>dog ^? _As @"Cat"Nothing>>>cat ^? _As @"Cat"Just ("Mog", 5)>>>_As @"Cat" # ("Garfield", 6) :: AnimalCat ("Garfield", 6)>>>duck ^? _As @AgeJust 2
class AsConstructor ctor a s | s ctor -> a where Source #
Sums that have a constructor with a given name.
Methods
A prism that projects a named constructor from a sum. Compatible with the
  lens package's Prism type.
>>>dog ^? _Ctor @"Dog"Just (MkDog {name = "Shep", age = 3})
>>>dog ^? _Ctor @"Cat"Nothing
>>>cat ^? _Ctor @"Cat"Just ("Mog", 5)
>>>_Ctor @"Cat" # ("Garfield", 6) :: AnimalCat ("Garfield", 6)
class AsType a s where Source #
Sums that have a constructor with a field of the given type.
Methods
A prism that projects a constructor uniquely identifiable by the type of
  its field. Compatible with the lens package's Prism type.
>>>dog ^? _Typed @DogJust (MkDog {name = "Shep", age = 3})>>>dog ^? _Typed @CatNothing>>>duck ^? _Typed @AgeJust 2