forked from mrkkrp/megaparsec
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mrkkrp#106] Patterns boolean algebra (mrkkrp#192)
* [mrkkrp#106] Patterns boolean algebra Resolves mrkkrp#106 * Add more tests * Better test names, consistency
- Loading branch information
Showing
14 changed files
with
159 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{- | | ||
Copyright: (c) 2020 Kowainik | ||
SPDX-License-Identifier: MPL-2.0 | ||
Maintainer: Kowainik <xrom.xkov@gmail.com> | ||
Embedded DSL for patterns (AST and Type). Implemented using the | ||
/Final Taggless/ approach. | ||
-} | ||
|
||
module Stan.Pattern.Edsl | ||
( PatternBool (..) | ||
) where | ||
|
||
{- | Common interface for 'Bool'-like parts of patterns. Allows to | ||
write composable and reusable complex pattern definitions from smaller | ||
pieces. | ||
Laws (in terms of matching functions that return 'Bool'): | ||
* @'(?)' ≡ 'True'@ | ||
* @'neg' '(?)' ≡ 'False'@ | ||
* @'(?)' '|||' x ≡ x '|||' '(?)' ≡ 'True'@ | ||
* @'(?)' '&&&' x ≡ x '&&&' '(?)' ≡ x@ | ||
-} | ||
class PatternBool a where | ||
-- | Anything. Matching should always return 'True'. | ||
(?) :: a | ||
|
||
-- | Negation. Inverses the argument. | ||
neg :: a -> a | ||
|
||
-- | Or-pattern. Choice. | ||
(|||) :: a -> a -> a | ||
|
||
-- | And-pattern. Both. | ||
(&&&) :: a -> a -> a | ||
|
||
infixr 2 ||| | ||
infixr 3 &&& |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters