Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- grammarFor :: Name -> ExpQ
- match :: Name -> ExpQ
- constructors :: Dec -> Maybe (Bool, [Con])
- findConstructor :: Name -> [Con] -> Maybe Con
- constructorNames :: Con -> Set Name
- fieldTypes :: Con -> [Type]
Documentation
grammarFor :: Name -> ExpQ Source #
Build a prism and the corresponding grammar that will match on the given constructor and convert it to reverse sequence of :- stacks.
E.g. consider a data type:
data FooBar a b c = Foo a b c | Bar
For constructor Foo
fooGrammar = $(grammarFor 'Foo)
will expand into
fooGrammar = PartialIso (\(c :- b :- a :- t) -> Foo a b c :- t) (\case { Foo a b c :- t -> Just $ c :- b :- a :- t; _ -> Nothing })
Note the order of elements on the stack:
ghci> :t fooGrammar fooGrammar :: Grammar p (c :- (b :- (a :- t))) (FooBar a b c :- t)
match :: Name -> ExpQ Source #
Build prisms and corresponding grammars for all data constructors of given type. Expects grammars to zip built ones with.
$(match ''Maybe)
Will expand into a lambda:
(\nothingG justG -> ($(grammarFor 'Nothing) . nothingG) <> ($(grammarFor 'Just) . justG))
fieldTypes :: Con -> [Type] Source #