HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerere-0.2.0.2Haskell2010

RERE

Regular-expressions extended with fixpoints for context-free powers.

Some examples are in RERE.Examples module.

  • 8 types
  • 24 values
  • Packagerere-0.2.0.2
  • Exports32
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceRERE.hs

Regular expressions with fixpoints

1 declaration
datadata RE a
#

Regular expression with fixed point.

Constructors

Instances11Monad, Functor, Applicative, Foldable, Traversable, Eq, …

Smart constructors

value(>>>=) :: Ord b => RE a -> (a -> RE b) -> RE b
#

Variable substitution.

Operations

valuenullable :: RE a -> Bool
#

Whether the regular expression accepts empty string, or whether the formal language contains empty string.

Example1 expression
nullable EpsTrue
Example1 expression
nullable (ch_ 'c')False
valuecompact :: Ord a => RE a -> RE a
#

Re-apply smart constructors on RE structure, thus potentially making it smaller.

This function is slow.

valuesize :: RE a -> Int
#

Size of RE. Counts constructors.

Matching

valuematch :: RE Void -> String -> Bool
#

Match string by iteratively differentiating the regular expression.

This version is slow, consider using RERE.matchR.

Generation

valuegenerate
  1. :: Int

    star upper size

  2. -> Int

    fix unroll

  3. -> RE Void
  4. -> Maybe (Gen String)
#

Generate strings.

Example1 expression
runGen 43 $ generate 10 10 $ star_ (ch_ 'a')"aaaaaaaaaa"
Example1 expression
runGen 44 $ generate 10 10 $ star_ (ch_ 'a')"aaa"

Variables

3 declarations
datadata Var a
#

Var is essentially Maybe.

Constructors

  • B

    bound

  • F a

    free variable.

Instances7Functor, Foldable, Traversable, Eq, Ord, Show, …
datadata Name
#

Names carry information used in pretty-printing, but otherwise they all compare EQual.

Instances4Eq, Ord, Show, IsString
  • Eq NameDefined in rere-0.2.0.2 · RERE.Var
  • Ord NameDefined in rere-0.2.0.2 · RERE.Var
  • Show NameDefined in rere-0.2.0.2 · RERE.Var
  • IsString NameDefined in rere-0.2.0.2 · RERE.Var

Context-free grammars

3 declarations
typetype CFG (n :: Nat) a = Vec n (CFGBase n a)
#

Context-free grammar represented as n equations of RE (CFGBase) with n variables.

valuecfgToRE :: (SNatI n, Ord a) => Vec ('S n) Name -> CFG ('S n) a -> RE a
#

Convert CFG (with names for productions) into RE. Note: the start symbol have to be last equation.

Example3 expressions
let a = Eps \/ ch_ 'a' <> Var (Left FZ)let b = Eps \/ ch_ 'b' <> Var (Left (FS FZ))let cfg = b ::: a ::: VNil

[ begin{aligned} {mathit{b}} &= {varepsilon}cupmathtt{b}{mathit{a}} -- {mathit{a}} &= {varepsilon}cupmathtt{a}{mathit{b}} -- end{aligned}

Faster matching

0 declarations

Ref

datadata RR s
#

Knot-tied recursive regular expression.

Instances1Show
  • Show (RR s)Defined in rere-0.2.0.2 · RERE.Ref

ST

datadata RST s
#

Knot-tied recursive regular expression.

Instances1Show
  • Show (RST s)Defined in rere-0.2.0.2 · RERE.ST

Character classes

3 declarations
typetype CharClasses = Set Char
#

Character classes are represented by partition lower bounds.

valuecharClasses :: RE a -> CharClasses
#

Character classes.

We can partition Char so characters in each part, affect the given regular expression in the same way.

If we do some kind of memoising, we can map all characters to classOfChar, making everything smaller.

Pretty printing (as LaTeX)

3 declarations