Safe Haskell | None |
---|---|
Language | Haskell2010 |
TemplateHaskell helpers
grammarFor :: Name -> ExpQ #
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)