cryptol-2.9.0: Cryptol: The Language of Cryptography

Cryptol.Utils.Patterns

Synopsis

# Documentation

newtype Match b Source #

Constructors

 Match (forall r. r -> (b -> r) -> r)
Instances
 Source # Instance detailsDefined in Cryptol.Utils.Patterns Methods(>>=) :: Match a -> (a -> Match b) -> Match b #(>>) :: Match a -> Match b -> Match b #return :: a -> Match a #fail :: String -> Match a # Source # Instance detailsDefined in Cryptol.Utils.Patterns Methodsfmap :: (a -> b) -> Match a -> Match b #(<\$) :: a -> Match b -> Match a # Source # Instance detailsDefined in Cryptol.Utils.Patterns Methodsfail :: String -> Match a # Source # Instance detailsDefined in Cryptol.Utils.Patterns Methodspure :: a -> Match a #(<*>) :: Match (a -> b) -> Match a -> Match b #liftA2 :: (a -> b -> c) -> Match a -> Match b -> Match c #(*>) :: Match a -> Match b -> Match b #(<*) :: Match a -> Match b -> Match a # Source # Instance detailsDefined in Cryptol.Utils.Patterns Methodsempty :: Match a #(<|>) :: Match a -> Match a -> Match a #some :: Match a -> Match [a] #many :: Match a -> Match [a] # Source # Instance detailsDefined in Cryptol.Utils.Patterns Methodsmzero :: Match a #mplus :: Match a -> Match a -> Match a #

type Pat a b = a -> Match b Source #

(|||) :: Pat a b -> Pat a b -> Pat a b Source #

(&&&) :: Pat a b -> Pat a c -> Pat a (b, c) Source #

Check that a value satisfies multiple patterns. For example, an "as" pattern is (__ &&& p).

(~>) :: Pat a b -> (b -> c) -> Pat a c Source #

Match a value, and modify the result.

(~~>) :: Pat a b -> c -> Pat a c Source #

Match a value, and return the given result

(<~) :: (a -> b) -> Pat b c -> Pat a c Source #

View pattern.

__ :: Pat a a Source #

Variable pattern.

succeed :: a -> Pat x a Source #

Constant pattern.

checkThat :: (a -> Bool) -> Pat a () Source #

Predicate pattern

lit :: Eq a => a -> Pat a () Source #

Check for exact value.

matchDefault :: a -> Match a -> a Source #

Match a pattern, using the given default if valure.

match :: Match a -> a Source #

Match an irrefutable pattern. Crashes on faliure.

list :: [Pat a b] -> Pat [a] [b] Source #

(><) :: Pat a b -> Pat x y -> Pat (a, x) (b, y) Source #

class Matches thing pats res | pats -> thing res where Source #

Methods

matches :: thing -> pats -> Match res Source #

Instances
 (f ~ Pat a a1', a1 ~ Pat a1' r1) => Matches a (f, a1) r1 Source # Instance detailsDefined in Cryptol.Utils.Patterns Methodsmatches :: a -> (f, a1) -> Match r1 Source # (op ~ Pat a (a1', a2'), a1 ~ Pat a1' r1, a2 ~ Pat a2' r2) => Matches a (op, a1, a2) (r1, r2) Source # Instance detailsDefined in Cryptol.Utils.Patterns Methodsmatches :: a -> (op, a1, a2) -> Match (r1, r2) Source # (op ~ Pat a (a1', a2', a3'), a1 ~ Pat a1' r1, a2 ~ Pat a2' r2, a3 ~ Pat a3' r3) => Matches a (op, a1, a2, a3) (r1, r2, r3) Source # Instance detailsDefined in Cryptol.Utils.Patterns Methodsmatches :: a -> (op, a1, a2, a3) -> Match (r1, r2, r3) Source #