Module

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

#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

#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

#Transit Source

data Transit

Base 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

#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

#WithGuard Source

data WithGuard :: forall k1 k2. k1 -> k2 -> Typedata WithGuard a b

Internal type for adding a guard condition to a return. Used with the :? operator.

Instances

#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

#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