vv_7ta
Last Updated: February 25, 2016
·
1.008K
· maloi
2b3044532f63d324a7601e3fe36a6980

Pattern Synonyms

From [1] "This patch implements Pattern Synonyms (enabled by -XPatternSynonyms), allowing you to assign names to a pattern and abstract over it."

Given

data Type = App String [Type]

you had to write something like

collectArgs (App "->" [t1, t2]) = t1 : collectArgs t2

With pattern synonyms like

pattern Arrow t1 t2 = App "->" [t1, t2]

you can now write

collectArgs (Arrow t1 t2) = t1 : collectArgs t2

More info at [2]

[1] http://www.haskell.org/pipermail/ghc-commits/2014-January/005722.html

[2] https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms

Say Thanks
Respond