OrPatterns

A quasiquoter for or-patterns

Latest on Hackage:0.1

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed and maintained by Adam Vogt

A quasiquoter for or-patterns. It allows one additional form for patterns:

f [o| p1 | p2 | p3 |] = rhs

Above, p1, p2 and p3 are three arbitrary patterns that bind the same variables. These variables are available in the expression rhs. Nesting of or-patterns is not supported yet.

See also:

g :: Either (x, y) (y, x) -> (x, y)
g [o| Left (x,y) | Right (y,x) |] = (x,y)
-- ends up slightly longer
g = elim $ left (pair var var) \/ right flipped ->> (,)
 where
  flipped = (\(a,b) -> (b,a)) --> pair var var
comments powered byDisqus