any-pat-0.2.0.0: Quasiquoters that act on a sequence of patterns and compiles these view into patterns and expressions.
Maintainerhapytexeu+gh@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Pattern.Any

Description

The module exposes two QuasiQuoters named anypat and maypat that allow compiling separate patterns into a single (view) pattern that will fire in case any of the patterns matches. If there are any variable names, it will match these. For the anypat it requires that all variables occur in all patterns. For maypat that is not a requirement. For both QuasiQuoters, it is however required that the variables have the same type in each pattern.

Synopsis

Quasiquoters

anypat Source #

Arguments

:: QuasiQuoter

The quasiquoter that can be used as expression and pattern.

A quasquoter to specify multiple patterns that will succeed if any of the patterns match. All patterns should have the same set of variables and these should have the same type, otherwise a variable would have two different types, and if a variable is absent in one of the patterns, the question is what to pass as value.

maypat Source #

Arguments

:: QuasiQuoter

The quasiquoter that can be used as expression and pattern.

A quasiquoter to specify multiple patterns that will succeed if any of these patterns match. Patterns don't have to have the same variable names but if a variable is shared over the different patterns, it should have the same type. In case a variable name does not appear in all patterns, it will be passed as a Maybe to the clause with Nothing if a pattern matched without that variable name, and a Just if the (first) pattern that matched had such variable.

rangepat Source #

Arguments

:: QuasiQuoter

The quasiquoter that can be used as expression and pattern.

A QuasiQuoter to parse a range expression to a RangeObj. In case the QuasiQuoter is used for a pattern, it compiles into a view pattern that will work if the element is a member of the RangeObj.

derive variable names names from patterns

patVars Source #

Arguments

:: Pat

The Pattern to inspect.

-> [Name]

The list of variable names that is used to collect (fragments) of the pattern.

Provides a list of variable names for a given Pattern. The list is not sorted. If the same variable name occurs multiple times (which does not make much sense), it will be listed multiple times.

patVars' Source #

Arguments

:: Pat

The Pattern to inspect.

-> [Name]

The list of remaining elements that is added as tail.

-> [Name]

The list of variable names that is used to collect (fragments) of the pattern.

Provides a list of variable names for a given Pattern. The list is not sorted. If the same variable name occurs multiple times (which does not make much sense), it will be listed multiple times.

Range objects

data RangeObj a Source #

A RangeObj that specifies a range with a start value and optionally a step value and end value.

Constructors

FromRange a

A RangeObj object that only has a start value, in Haskell specified as [b ..].

FromThenRange a a

A RangeObj object that has a start value and end value, in Haskell specified as [b .. e].

FromToRange a a

A RangeObj object with a start and next value, in Haskell specified as [b, s ..].

FromThenToRange a a a

A RangeObj object with a start, next value and end value, in Haskell specified as [b, s .. e].

Instances

Instances details
Functor RangeObj Source # 
Instance details

Defined in Data.Pattern.Any

Methods

fmap :: (a -> b) -> RangeObj a -> RangeObj b #

(<$) :: a -> RangeObj b -> RangeObj a #

Read a => Read (RangeObj a) Source # 
Instance details

Defined in Data.Pattern.Any

Show a => Show (RangeObj a) Source # 
Instance details

Defined in Data.Pattern.Any

Methods

showsPrec :: Int -> RangeObj a -> ShowS #

show :: RangeObj a -> String #

showList :: [RangeObj a] -> ShowS #

Eq a => Eq (RangeObj a) Source # 
Instance details

Defined in Data.Pattern.Any

Methods

(==) :: RangeObj a -> RangeObj a -> Bool #

(/=) :: RangeObj a -> RangeObj a -> Bool #

rangeToList Source #

Arguments

:: Enum a 
=> RangeObj a

The RangeObj item to convert to a list.

-> [a]

A list of items the RangeObj spans.

Convert the RangeObj to a list of the values defined by the range.

inRange Source #

Arguments

:: Enum a 
=> RangeObj a

The RangeObj for which we check membership.

-> a

The element for which we check the membership.

-> Bool 

Check if the given value is in the given RangeObj. This function has some caveats, especially with floating points or other Enum instances where fromEnum and toEnum are no bijections. For example for floating points, `12.5` and `12.2` both map on the same item, as a result, the enum will fail to work properly.