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 |
Derive constructor-name-based prisms generically.
- class AsConstructor ctor a s | s ctor -> a where
Prisms
class AsConstructor ctor a s | s ctor -> a where Source #
Sums that have a constructor with a given name.
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) :: Animal
Cat ("Garfield", 6)