first-class-patterns-0.3.2.5: First class patterns and pattern matching, using type families

LicenseBSD3
MaintainerBrent Yorgey <byorgey@cis.upenn.edu>
Stabilityexperimental
Portabilitynon-portable (see .cabal)
Safe HaskellNone
LanguageHaskell2010

Data.Pattern.Base

Contents

Description

The main types used in the implementation of first-class patterns: Pattern and Clause.

Synopsis

Patterns

newtype Pattern vars a Source #

The pattern type. A value of type Pattern vars a is a pattern which matches values of type a and binds variables with types given by the type-list vars. For example, something of type

Pattern (a :*: c :*: Nil) (a,b,c)

is a pattern which matches against a triple and binds values of types a and c. (A pattern of this type can be constructed as tup3 var __ var.)

Many "normal" patterns can be conveniently defined using mk0, mk1, mk2, and so on.

Constructors

Pattern 

Fields

Clauses

data Clause a r Source #

Pattern-match clauses. Typically something of the form

pattern ->> function

where the function takes one argument for each variable bound by the pattern.

Clauses can be constructed with (->>), run with tryMatch, and manipulated by the Monad and MonadPlus instances. In particular, the (<|>) operator from the Alternative class is the way to list multiple cases in a pattern.

Instances
Monad (Clause a) Source # 
Instance details

Defined in Data.Pattern.Base

Methods

(>>=) :: Clause a a0 -> (a0 -> Clause a b) -> Clause a b #

(>>) :: Clause a a0 -> Clause a b -> Clause a b #

return :: a0 -> Clause a a0 #

fail :: String -> Clause a a0 #

Functor (Clause a) Source # 
Instance details

Defined in Data.Pattern.Base

Methods

fmap :: (a0 -> b) -> Clause a a0 -> Clause a b #

(<$) :: a0 -> Clause a b -> Clause a a0 #

Applicative (Clause a) Source # 
Instance details

Defined in Data.Pattern.Base

Methods

pure :: a0 -> Clause a a0 #

(<*>) :: Clause a (a0 -> b) -> Clause a a0 -> Clause a b #

liftA2 :: (a0 -> b -> c) -> Clause a a0 -> Clause a b -> Clause a c #

(*>) :: Clause a a0 -> Clause a b -> Clause a b #

(<*) :: Clause a a0 -> Clause a b -> Clause a a0 #

Alternative (Clause a) Source # 
Instance details

Defined in Data.Pattern.Base

Methods

empty :: Clause a a0 #

(<|>) :: Clause a a0 -> Clause a a0 -> Clause a a0 #

some :: Clause a a0 -> Clause a [a0] #

many :: Clause a a0 -> Clause a [a0] #

MonadPlus (Clause a) Source # 
Instance details

Defined in Data.Pattern.Base

Methods

mzero :: Clause a a0 #

mplus :: Clause a a0 -> Clause a a0 -> Clause a a0 #

runClause :: Clause a r -> ReaderT a Maybe r Source #

Extract the underlying computation constituting a Clause. This function is not intended to be used directly; instead, see match, tryMatch, mmatch, and elim from Data.Pattern.Common.

(->>) :: Pattern vars a -> Fun vars r -> Clause a r infix 4 Source #

Construct a Clause from a pattern and a function which takes one argument for each variable bound by the pattern. For example,

pair __ nothing     ->> 3
pair var nothing    ->> \x -> x + 3
pair var (just var) ->> \x y -> x + y + 3

(<|>) :: Alternative f => f a -> f a -> f a infixl 3 #

An associative binary operation

Internals