Transit.DSL
- Package
- purescript-transit
- Repository
- m-bock/purescript-transit
Domain-Specific Language (DSL) for building type-level transit specifications.
This module provides a type-level DSL for constructing state machine specifications in a declarative way. The DSL uses infix operators to create readable specifications that are automatically converted to transit cores.
Basic Usage
type MyTransit =
Transit
:* ("State1" :@ "Msg1" >| "State2")
:* ("State2" :@ "Msg2" >| "State1")
Operators
:*- Add a match/transition to the specification:@- Combine state and message (e.g.,"State1" :@ "Msg1")>|- Add return state(s) to a match|<- Create bidirectional edge (e.g.,"State1" |< "Msg" >| "State2"):?- Add guard condition to a return (e.g.,"guard" :? "State2")
#type (:*) Source
Operator alias for Transit.DSL.AddMatch (right-associative / precedence 0)
Infix operator for adding matches to a transit specification.
Right-associative, allowing Transit to appear first for clean indentation.
Example: Transit :* ("State1" :@ "Msg1" >| "State2")
#AddMatch Source
data AddMatch :: forall k1 k2. k1 -> k2 -> Typedata AddMatch a b
Internal type for adding a match to a transit specification.
Used with the :* operator.
Instances
(IsTransitSpec (AddMatch a b) o, Reflectable o TransitCore) => Reflectable (AddMatch a b) TransitCore(ToTransitCore (AddMatch a b) c) => IsTransitSpec (AddMatch a b) cTransit specification with matches added via
:*.(ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch Transit xs) (MkTransitCoreTL ys)(ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch (AddOut (AddIn s1 ms) s2) xs) (MkTransitCoreTL (Cons' (MkMatchTL s1 ms (Cons' (MkReturnTL s2) Nil')) (Cons' (MkMatchTL s2 ms (Cons' (MkReturnTL s1) Nil')) ys)))(ToMatch x t, ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch x xs) (MkTransitCoreTL (Cons' t ys))
#type (:?) Source
Operator alias for Transit.DSL.WithGuard (left-associative / precedence 9)
Infix operator for adding guard conditions to returns.
Example: "guard" :? "State2"
#type (:@) Source
Operator alias for Transit.DSL.StateWithMsg (left-associative / precedence 5)
Infix operator for combining a state with a message.
Example: "State1" :@ "Msg1"
#type (>|) Source
Operator alias for Transit.DSL.AddOut (left-associative / precedence 5)
Infix operator for adding return states to a match.
Example: "State1" :@ "Msg1" >| "State2" >| "State3"
#type (|<) Source
Operator alias for Transit.DSL.AddIn (left-associative / precedence 5)
Infix operator for creating bidirectional edges.
Example: "State1" |< "Msg" >| "State2" creates edges in both directions.
#ToTransitCore Source
class ToTransitCore :: forall k. k -> TransitCoreTL -> Constraintclass ToTransitCore dsl a | dsl -> a
Type class that converts DSL expressions to transit core specifications.
This class is used internally to transform the DSL syntax into the underlying transit core type-level representation.
Instances
ToTransitCore Transit (MkTransitCoreTL Nil')(ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch Transit xs) (MkTransitCoreTL ys)(ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch (AddOut (AddIn s1 ms) s2) xs) (MkTransitCoreTL (Cons' (MkMatchTL s1 ms (Cons' (MkReturnTL s2) Nil')) (Cons' (MkMatchTL s2 ms (Cons' (MkReturnTL s1) Nil')) ys)))ToTransitCore (AddOut (AddIn s1 ms) s2) (MkTransitCoreTL (Cons' (MkMatchTL s1 ms (Cons' (MkReturnTL s2) Nil')) (Cons' (MkMatchTL s2 ms (Cons' (MkReturnTL s1) Nil')) Nil')))(ToMatch x t, ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch x xs) (MkTransitCoreTL (Cons' t ys))(ToMatch x t) => ToTransitCore x (MkTransitCoreTL (Cons' t Nil'))
#ToMatch Source
class ToMatch :: forall k. k -> MatchTL -> Constraintclass ToMatch dsl a | dsl -> a
Type class that converts DSL match expressions to match specifications.
Handles conversion of state-message combinations and return states into the underlying match type-level representation.
Instances
#ToReturn Source
class ToReturn :: forall k. k -> ReturnTL -> Constraintclass ToReturn dsl a | dsl -> a
Type class that converts DSL return expressions to return specifications.
Handles conversion of state names and guard conditions into the underlying return type-level representation.
Instances
ToReturn (WithGuard g s) (MkReturnViaTL g s)ToReturn s (MkReturnTL s)
#Transit Source
data TransitBase type for transit specifications (empty specification).
Start all transit specifications with Transit, then add matches using :*.
Example:
type MyTransit =
Transit
:* ("State1" :@ "Msg1" >| "State2")
:* ("State2" :@ "Msg2" >| "State3")
Instances
IsTransitSpec Transit (MkTransitCoreTL Nil')Empty transit specification (no matches).
ToTransitCore Transit (MkTransitCoreTL Nil')(ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch Transit xs) (MkTransitCoreTL ys)
#StateWithMsg Source
data StateWithMsg :: forall k1 k2. k1 -> k2 -> Typedata StateWithMsg a b
Internal type for combining a state with a message.
Used with the :@ operator.
Instances
ToMatch (StateWithMsg x y) (MkMatchTL x y Nil')
#AddOut Source
data AddOut :: forall k1 k2. k1 -> k2 -> Typedata AddOut a b
Internal type for adding an output (return state).
Used with the >| operator.
Instances
(ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch (AddOut (AddIn s1 ms) s2) xs) (MkTransitCoreTL (Cons' (MkMatchTL s1 ms (Cons' (MkReturnTL s2) Nil')) (Cons' (MkMatchTL s2 ms (Cons' (MkReturnTL s1) Nil')) ys)))ToTransitCore (AddOut (AddIn s1 ms) s2) (MkTransitCoreTL (Cons' (MkMatchTL s1 ms (Cons' (MkReturnTL s2) Nil')) (Cons' (MkMatchTL s2 ms (Cons' (MkReturnTL s1) Nil')) Nil')))(ToMatch x (MkMatchTL s m xs), ToReturn y y') => ToMatch (AddOut x y) (MkMatchTL s m (Cons' y' xs))ToMatch (AddOut (AddIn x y) z) (MkMatchTL x y Nil')
#AddIn Source
data AddIn :: forall k1 k2. k1 -> k2 -> Typedata AddIn a b
Internal type for adding an input (bidirectional edge).
Used with the |< operator.
Instances
(ToTransitCore xs (MkTransitCoreTL ys)) => ToTransitCore (AddMatch (AddOut (AddIn s1 ms) s2) xs) (MkTransitCoreTL (Cons' (MkMatchTL s1 ms (Cons' (MkReturnTL s2) Nil')) (Cons' (MkMatchTL s2 ms (Cons' (MkReturnTL s1) Nil')) ys)))ToTransitCore (AddOut (AddIn s1 ms) s2) (MkTransitCoreTL (Cons' (MkMatchTL s1 ms (Cons' (MkReturnTL s2) Nil')) (Cons' (MkMatchTL s2 ms (Cons' (MkReturnTL s1) Nil')) Nil')))ToMatch (AddOut (AddIn x y) z) (MkMatchTL x y Nil')
- Modules
- Transit
- Transit.
Class. CheckReturn - Transit.
Class. CurryN - Transit.
Class. MkHandlerLookup - Transit.
Class. MkUpdate - Transit.
Core - Transit.
DSL - Transit.
Data. DotLang - Transit.
Data. Graph - Transit.
Data. Html - Transit.
Data. MaybeChurch - Transit.
Data. Table - Transit.
HandlerLookup - Transit.
Render. Graphviz - Transit.
Render. Theme - Transit.
Render. TransitionTable - Transit.
StateGraph - Transit.
VariantUtils
Allows DSL specifications to be reflected to runtime TransitCore values.