|Maintainer||Reiner Pope <firstname.lastname@example.org>|
Common pattern combinators.
- var :: Pattern (a :*: Nil) a
- __ :: Pat0 a
- (/\) :: Pat2 a a a
- (\/) :: Pattern as a -> Pattern as a -> Pattern as a
- view :: (a -> b) -> Pat1 b a
- tryView :: (a -> Maybe b) -> Pat1 b a
- is :: (a -> Bool) -> Pat0 a
- cst :: Eq a => a -> Pat0 a
- elim :: Clause a r -> a -> r
- mmatch :: Monad m => m a -> Clause a (m b) -> m b
- mk0 :: (a -> Maybe ()) -> Pat0 a
- mk1 :: (a -> Maybe b) -> Pat1 b a
- mk2 :: (a -> Maybe (b, c)) -> Pat2 b c a
- mk3 :: (a -> Maybe (b, c, d)) -> Pat3 b c d a
- mk4 :: (a -> Maybe (b, c, d, e)) -> Pat4 b c d e a
- mk5 :: (a -> Maybe (b, c, d, e, f)) -> Pat5 b c d e f a
- tup0 :: Pat0 ()
- tup1 :: Pat1 a a
- tup2 :: Pat2 a b (a, b)
- tup3 :: Pat3 a b c (a, b, c)
- tup4 :: Pat4 a b c d (a, b, c, d)
- tup5 :: Pat5 a b c d e (a, b, c, d, e)
- left :: Pat1 a (Either a b)
- right :: Pat1 b (Either a b)
- nil :: Pat0 [a]
- cons :: Pat2 a [a] [a]
"Variable patterns": always succeeds, and binds the value to a variable.
"And patterns". Succeeds only if both patterns succeed.
mk2(a -> (a,a))
"Or patterns". If first pattern fails, then tries the second.
"View patterns": do some computation, then pattern match on the result.
"Constant patterns": tests for equality to the given constant.
cst x = is (==x)
mmatch m p = m >>=
Useful for applicative-looking monadic pattern matching, as in
ex7 :: IO () ex7 = mmatch getLine $ cst "" ->> return () <|> var ->> putStrLn . ("You said " ++)
Smart constructors for patterns
These build patterns from a selector function.