kleene-type-0

Safe HaskellNone
LanguageHaskell2010

Kleene.Type.Examples

Contents

Synopsis

Nullable

Nullable regular expression is regular expression which matches on empty list.

nullable1 :: forall xs. MatchI E xs => HList xs -> () Source #

RE is nullable.

nullable2 :: forall xs. MatchI (S (V Bool)) xs => HList xs -> [Bool] Source #

RE r for all r is nullable

nullable3 :: forall xs. MatchI (V Bool \/ E) xs => HList xs -> Maybe Bool Source #

r :\/ s is nullable if either r or s is nullable.

nullable4 :: forall xs. MatchI (E \/ V Bool) xs => HList xs -> Maybe Bool Source #

r :\/ s is nullable if either r or s is nullable.

nullable5 :: forall xs. MatchI (E <> E) xs => HList xs -> () Source #

r :<> s is nullable if both r or s are nullable.

nullable6 :: forall xs. MatchI (E <> (E <> S (V Bool))) xs => HList xs -> () Source #

Complex example.

Isomorphism examples

HList can be abused for many things:

Unit, tuples i.e. products

unitEx :: forall xs a. MatchI (V a) xs => HList xs -> a Source #

Unit

unitEx' :: a -> REList (V a) Source #

pairEx :: forall xs a b. MatchI (V a <> V b) xs => HList xs -> (a, b) Source #

Pair

pairEx' :: (a, b) -> REList (V a <> V b) Source #

tripleEx :: forall xs a b c. MatchI (V a <> (V b <> V c)) xs => HList xs -> (a, b, c) Source #

Triple

tripleExB :: forall xs a b c. MatchI ((V a <> V b) <> V c) xs => HList xs -> (a, b, c) Source #

Triple, associated other way

tripleExC :: forall xs b c. MatchI ((E <> V b) <> V c) xs => HList xs -> ((), b, c) Source #

Untagged sum

untaggedSumEx :: forall xs a b. MatchI (V a \/ V b) xs => HList xs -> Either a b Source #

Tagged sum

InL and InR are keywords, they act as proxies for themselves.

data InL Source #

Constructors

InL 
Instances
Eq InL Source # 
Instance details

Defined in Kleene.Type.Examples

Methods

(==) :: InL -> InL -> Bool #

(/=) :: InL -> InL -> Bool #

Show InL Source # 
Instance details

Defined in Kleene.Type.Examples

Methods

showsPrec :: Int -> InL -> ShowS #

show :: InL -> String #

showList :: [InL] -> ShowS #

data InR Source #

Constructors

InR 
Instances
Eq InR Source # 
Instance details

Defined in Kleene.Type.Examples

Methods

(==) :: InR -> InR -> Bool #

(/=) :: InR -> InR -> Bool #

Show InR Source # 
Instance details

Defined in Kleene.Type.Examples

Methods

showsPrec :: Int -> InR -> ShowS #

show :: InR -> String #

showList :: [InR] -> ShowS #

type Sum a b = (V InL <> V a) \/ (V InR <> V b) Source #

Think: Either, keywords make match less ambiguous.

taggedSumEx :: forall xs a b. MatchI (Sum a b) xs => HList xs -> Either a b Source #

Tagged union: "proper" Either.

List

listEx :: forall xs a. MatchI (S (V a)) xs => HList xs -> [a] Source #

List

listEx' :: [a] -> REList (S (V a)) Source #