-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example of an unrestricted machine with boolean state
- Loading branch information
Marco Perone
committed
Jan 26, 2023
1 parent
e8e04bf
commit 2273f57
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{-# LANGUAGE GADTs #-} | ||
|
||
module CRM.Example.BooleanStateMachine where | ||
|
||
import "crm" CRM.BaseMachine | ||
import "crm" CRM.StateMachine | ||
import "singletons-base" Data.Singletons.Base.TH | ||
|
||
booleanStateMachine | ||
:: forall a | ||
. SBool a | ||
-> StateMachine Int Int | ||
booleanStateMachine initialState = | ||
unrestrictedMachine @Bool | ||
( \state input -> case state of | ||
SFalse -> | ||
if even input | ||
then ActionResult SFalse (input + 1) | ||
else ActionResult STrue (input * 3) | ||
STrue -> | ||
if even input | ||
then ActionResult STrue (input - 1) | ||
else ActionResult SFalse (input * 5) | ||
) | ||
(InitialState initialState) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters