Copyright | Copyright (c) Jordan Woehr 2018 |
---|---|
License | BSD |
Maintainer | Jordan Woehr |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This module exports template haskell functions for generating tedious boilerplate.
Documentation
:: Name | The |
-> String | The label in the variant the constructor will have. |
-> String | The name of the fixed pattern. |
-> String | The name of the unfixed pattern. |
-> Q [Dec] |
Create patterns for a variant constructor.
For example, for the type FooF with the constructor FooF':
data FooF a x = FooF' a x $(mkVarPattern ''FooF "foo" "Foo" "FooF")
A pattern similar to the following will be generated:
pattern FooF :: (OpenAlg r "foo" (FooF a) v) => a -> v -> VarF r v pattern FooF a v <- VarF (view (Label :: Label "foo") -> Just (FooF' a v)) pattern Foo :: (OpenAlg r "foo" (FooF a) (OpenADT r)) => a -> OpenADT r -> OpenADT r where FooF a v = VarF (IsJust (Label :: Label "foo") (FooF' a v)) pattern Foo a v = Fix (FooF a v)