HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulerere-0.2.0.2Haskell2010

RERE.Examples

Various examples of using rere, as used in the blog post.

  • 20 values
  • Packagerere-0.2.0.2
  • Exports20
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceExamples.hs
Example6 expressions
import Test.QuickCheck.Random (mkQCGen)import Test.QuickCheck.Gen (unGen)import Control.Monad.ST (runST)import RERElet runGen seed = maybe "<<null>>" (\g' -> unGen g' (mkQCGen seed) 10)let showRef re = matchDebugR re ""

Syntax

1 declaration
valuesyntaxExamples :: IO ()
#

Demonstrates how various constructors are pretty printed.

Example 1

2 declarations
valueex1 :: RE Void
#
Example1 expression
match ex1 "abab"True
Example1 expression
match ex1 "ababa"False
Example1 expression
ex1Star (App (Ch "a") (Ch "b"))
Example1 expression
charClasses ex1fromList "\NULabc"
Example1 expression
showRef ex1size: 4show: Star (App (Ch "a") (Ch "b"))null: True
Example1 expression
matchR ex1 "abab"True
Example1 expression
matchR ex1 "ababa"False
Example1 expression
runGen 43 (generate 10 20 ex1)"abababababababababab"
Example1 expression
runGen 44 (generate 10 20 ex1)"ababab"

Example 2

2 declarations
valueex2 :: RE Void
#
Example1 expression
match ex2 "aaa"True

Note: how "sharing" is preserved.

Example1 expression
showRef ex2size: 5show: App (Star (Ch "a")) (Star (Ch "a"))null: True
> matchR ex2 "aaa"

True

Example1 expression
runGen 42 (generate 10 20 ex2)"aaaaaa"
Example1 expression
runGen 44 (generate 10 20 ex2)"aaaaaaaaaa"

Example 3

2 declarations
valueex3 :: RE Void
#
Example1 expression
match ex3 "abab"True
Example1 expression
match ex3 "ababa"False
Example1 expression
showRef ex3size: 8show: Ref 0 (Alt Eps (App (Ch "a") (App (Ch "b") (Ref 0 <<loop>>))))null: True
Example1 expression
matchR ex3 "abab"True
Example1 expression
matchR ex3 "ababa"False
Example1 expression
runGen 43 (generate 10 20 ex3)"abababab"
Example1 expression
runGen 44 (generate 10 20 ex3)"abab"

Example 4

2 declarations
valueex4 :: RE Void
#
Example1 expression
match ex4 "aaaabbbb"True
Example1 expression
showRef ex4size: 8show: Ref 0 (Alt Eps (App (Ch "a") (App (Ref 0 <<loop>>) (Ch "b"))))null: True
Example1 expression
matchR ex4 "aaaabbbb"True
Example1 expression
runGen 43 (generate 10 20 ex4)"ab"
Example1 expression
runGen 47 (generate 10 20 ex4)"aaaabbbb"

Example 5

2 declarations
valueex5 :: RE Void
#
Example1 expression
match ex5 "abab"True
Example1 expression
match ex5 "ababa"False
Example1 expression
showRef ex5size: 8show: Ref 0 (Alt Eps (App (Ref 0 <<loop>>) (App (Ch "a") (Ch "b"))))null: True
Example1 expression
matchR ex5 "abab"True
Example1 expression
matchR ex5 "ababa"False
Example1 expression
runGen 43 (generate 10 20 ex5)"ab"
Example1 expression
runGen 51 (generate 10 20 ex5)"abab"

Example 6

2 declarations
valueex6 :: RE Void
#

Using fix-point operator:

fix expr = "(" expr ")" | "1" | "2" | ... | "9" | expr "+" expr | expr "*" expr

which in BNF is almost he same

expr ::= "(" expr ")" | "1" | "2" | ... | "9" | expr "+" expr | expr "*" expr
Example1 expression
matchR ex6 "(1+2)*3"True
Example1 expression
runGen 43 (generate 5 5 ex6)"74501+(534*19450)*(99050)"

Example 7

7 declarations
valueex7 :: Ord a => RE a
#
Example1 expression
matchR ex7 "12"True
Example1 expression
matchR ex7 "(1+2)*3"True
Example1 expression
charClasses ex7fromList "\NUL()*+,0:"
Example1 expression
runGen 43 (generate 5 5 ex7)"(3431*((0337+5+070346+4))+76848+((4126+350875)*98769+308194+270+03118)+888*(95+90904)+(301069+7+715835)+2809)"

Example 8

0 declarations

Example 9

0 declarations