View Source cure_fsm_typesafety (cure v0.7.0)
FSM Type Safety
This module provides enhanced type checking for FSM definitions, ensuring:
- State-dependent payload types
- Event type validation
- Guard type constraints
- Action type inference
Type Safety Features
- Payload Type Safety: Each state can have its own payload type
- Event Typing: Events are type-checked against expected types
- Guard Constraints: Guards refine types through constraints
- Action Safety: Actions preserve or transform types correctly
Usage
% Check FSM definition for type safety
case cure_fsm_typesafety:check_fsm_types(FsmDef, Env) of
{ok, TypedFsmDef} ->
io:format(\"FSM is type-safe~n\");
{error, TypeError} ->
io:format(\"Type error: ~p~n\", [TypeError])
end.
Summary
Functions
-spec check_action_types(FsmDef :: term(), FsmEnv :: #fsm_type_env{state_payload_types :: #{atom() => term()}, event_types :: #{atom() => term()}, guard_constraints :: [term()], global_env :: term()}) -> {ok, #fsm_type_env{state_payload_types :: #{atom() => term()}, event_types :: #{atom() => term()}, guard_constraints :: [term()], global_env :: term()}} | {error, term()}.
-spec check_event_types(FsmDef :: term(), FsmEnv :: #fsm_type_env{state_payload_types :: #{atom() => term()}, event_types :: #{atom() => term()}, guard_constraints :: [term()], global_env :: term()}) -> {ok, #fsm_type_env{state_payload_types :: #{atom() => term()}, event_types :: #{atom() => term()}, guard_constraints :: [term()], global_env :: term()}} | {error, term()}.
-spec check_guard_types(FsmDef :: term(), FsmEnv :: #fsm_type_env{state_payload_types :: #{atom() => term()}, event_types :: #{atom() => term()}, guard_constraints :: [term()], global_env :: term()}) -> {ok, #fsm_type_env{state_payload_types :: #{atom() => term()}, event_types :: #{atom() => term()}, guard_constraints :: [term()], global_env :: term()}} | {error, term()}.
-spec check_state_payload_types(FsmDef :: term(), FsmEnv :: #fsm_type_env{state_payload_types :: #{atom() => term()}, event_types :: #{atom() => term()}, guard_constraints :: [term()], global_env :: term()}) -> {ok, #fsm_type_env{state_payload_types :: #{atom() => term()}, event_types :: #{atom() => term()}, guard_constraints :: [term()], global_env :: term()}} | {error, term()}.