funpat-0.1: A generalization of pattern matching

Language.FunPat.Match

Contents

Synopsis

Matchability

data Match whereSource

A data type to be used in Matchable instances.

Constructors

:=: :: Matchable a => a -> a -> Match 

class Typeable a => Matchable a whereSource

Matchable data types can be used in patterns.

Methods

(.=.) :: a -> a -> Maybe [Match]Source

The conditions of a match. In most cases, this is the only function in this class to implement.

If the result is Nothing, there is no match.

If the result is Just [x :=: x', y :=: y', ... ], condition of the match is that x matches x', y matches y' etc.

makeParam :: Bool -> aSource

Creates an extra value of type a with a Bool inside.

The default implementation throws an exception.

isParam :: a -> Maybe BoolSource

Checks if the argument is an extra value created by makeParam.

The default implementation evaluates the argument and catches the exception thrown.

Implementation

data Param Source

Constructors

Param 

Fields

fromParam :: Bool
 

class Matchable (PatternType t) => Case t whereSource

Case instances are allowed to form cases of a pattern match. (Normally, there is no need to implement more instances of this class.)

Associated Types

type PatternType t Source

type ResultType t Source

type ParameterType t Source

Instances

(Typeable p, Matchable p, Case u) => Case (p -> u) 
(Matchable u, Typeable u) => Case (u, v) 

data SomeCase t whereSource

Constructors

SomeCase :: Case a => a -> SomeCase (PatternType a, ResultType a) 

matchSomeCase :: pat -> SomeCase (pat, res) -> Maybe resSource

Processes one case.

matchCases :: pat -> [SomeCase (pat, res)] -> resSource

Processes multiple cases.

matchHelp :: Typeable p => Match -> p -> Maybe [p]Source

matchFold :: Typeable p => p -> [Match] -> Maybe [p]Source

Helper functions