funpat-0.1: A generalization of pattern matching





data Match whereSource

A data type to be used in Matchable instances.


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

class Typeable a => Matchable a whereSource

Matchable data types can be used in patterns.


(.=.) :: 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.


data Param Source




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


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

data SomeCase t whereSource


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