License | BSD-3-Clause |
---|---|
Maintainer | Jamie Willis |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This module contains CharPred
, a specialised defunctionalising for Char -> Bool
functions.
This can be used to efficiently query for character class membership.
Since: 2.1.0.0
Synopsis
- data CharPred where
- pattern Item :: CharPred
- pattern Specific :: Char -> CharPred
- apply :: CharPred -> Char -> Bool
- andPred :: CharPred -> CharPred -> CharPred
- orPred :: CharPred -> CharPred -> CharPred
- diffPred :: CharPred -> CharPred -> CharPred
- optimisePredGiven :: CharPred -> CharPred -> CharPred
- members :: CharPred -> [Char]
- nonMembers :: CharPred -> [Char]
- lamTerm :: CharPred -> Lam (Char -> Bool)
Documentation
Represents Char -> Bool
functions, potentially in a more inspectable way.
Since: 2.1.0.0
apply :: CharPred -> Char -> Bool Source #
Tests whether a given character falls within the predicate.
Since: 2.1.0.0
andPred :: CharPred -> CharPred -> CharPred Source #
Merges two predicates by creating one which only returns true when a character is in both original predicates.
Since: 2.1.0.0
orPred :: CharPred -> CharPred -> CharPred Source #
Merges two predicates by creating one which only returns true when a character is in either of the original predicates.
Since: 2.1.0.0
diffPred :: CharPred -> CharPred -> CharPred Source #
Merges two predicates by creating one which only returns true when a character is in the first but not the second predicate.
Since: 2.1.0.0
:: CharPred | A predicate to be optimised with previous given knowledge. |
-> CharPred | A predicate that is known to already be true. |
-> CharPred |
Occasionally, characters can pass through a predicate only to pass through another at a later point. This given information can be used to optimise the new predicate the character is fed through.
This works as follows:
- If the given knowledge is a subset of the new predicate, then we know that any character check
will have passed, because it already passed a stricter check. The predicate can, therefore, be
optimised to
Item
. - Otherwise, the character can only pass through both predicates if it can pass through their intersection. If the intersection is smaller (in terms of the number of checks required to establish membership), then it should be used as it generates smaller code.
- If neither of the above conditions are true, then the original predicate remains the most efficient for future tests.
Since: 2.1.0.0
members :: CharPred -> [Char] Source #
Given a predicate, returns the full range of characters it returns True
for.
Since: 2.1.0.0
nonMembers :: CharPred -> [Char] Source #
Given a predicate, returns the full range of characters it returns False
for.
Since: 2.1.0.0