| Copyright | (C) 2018 Csongor Kiss |
|---|---|
| License | BSD3 |
| Maintainer | Csongor Kiss <kiss.csongor.kiss@gmail.com> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.Generics.Sum.Any
Contents
Description
Derive a variety of prisms generically.
Prisms
Running example:
>>>:set -XTypeApplications>>>:set -XDataKinds>>>:set -XDeriveGeneric>>>import GHC.Generics>>>:m +Data.Generics.Internal.VL.Prism>>>:{data Animal = Dog Dog | Cat Name Age | Duck Age deriving (Generic, Show) data Dog = MkDog { name :: Name , age :: Age } deriving (Generic, Show) type Name = String type Age = Int dog, cat, duck :: Animal dog = Dog (MkDog "Shep" 3) cat = Cat "Mog" 5 duck = Duck 2 :}
class AsAny (sel :: k) 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 @(Name, Age)Just ("Mog",5)
>>>cat ^? _As @"Cat"Just ("Mog",5)
>>>_As @"Cat" # ("Garfield", 6) :: AnimalCat "Garfield" 6
>>>duck ^? _As @AgeJust 2