{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
module Kleene.Classes where
import Prelude ()
import Prelude.Compat
import Algebra.Lattice (BoundedJoinSemiLattice (..), joins)
import Data.Foldable (toList)
import Data.Function.Step.Discrete.Closed (SF)
import Data.Map (Map)
import Data.RangeSet.Map (RSet)
import Kleene.Internal.Sets (dotRSet)
class (BoundedJoinSemiLattice k, Semigroup k, Monoid k) => Kleene c k | k -> c where
empty :: k
empty = bottom
eps :: k
eps = mempty
char :: c -> k
appends :: [k] -> k
appends = mconcat
unions :: [k] -> k
unions = joins
star :: k -> k
oneof :: (Kleene c k, Foldable f) => f c -> k
oneof = unions . map char . toList
class Kleene c k => FiniteKleene c k | k -> c where
everything :: k
everything = star anyChar
charRange :: c -> c -> k
fromRSet :: RSet c -> k
dot :: c ~ Char => k
dot = fromRSet dotRSet
anyChar :: k
class Derivate c k | k -> c where
nullable :: k -> Bool
derivate :: c -> k -> k
class Match c k | k -> c where
match :: k -> [c] -> Bool
class Match c k => Equivalent c k | k -> c where
equivalent :: k -> k -> Bool
class Derivate c k => TransitionMap c k | k -> c where
transitionMap :: k -> Map k (SF c k)
class Complement c k | k -> c where
complement :: k -> k