is-0.1: Pattern predicates using TH

Safe HaskellNone
LanguageHaskell2010

Data.Generics.Is

Contents

Description

Generate predicates from constructor names or from quoted patterns.

You must enable the TemplateHaskell extension to use this module

Synopsis

From constructors

Given a constructor for type T, is generates a function of type T -> Bool.

The function evaluates its argument to WHNF, and returns True if the head constructor matches the given one, False otherwise.

$(isNot 'Con) ≡ not . $(is 'Con)
>>> $(is 'Just) (Just 5)
True
>>> $(isNot 'Left) (Left "a")
False

From patterns

Given a pattern for type T, isP generates a function of type T -> Bool.

The function returns True if the expression matches the pattern; a and False otherwise.

$(isNot patQ) ≡ not . $(isP patQ)
$(isP [p| Con{} |]) ≡ $(is 'Con)
>>> $(isP [p| Just _ |]) Nothing
False
>>> $(isNotP [_,_,_]) [2,1]
True