Hi everyone, I have developed a new library typed-fsm.
It allows writing typed finite state machines.
It has many advantages:
Focus on the right message
Top-to-bottom design for easy refactoring
Conducive to building complex state machine systems
Type guarantees will not produce incorrect function calls when written
With the help of the type system, we can define many state processing functions and then call each other recursively with confidence.
There is a sanity check. If you miss some items for pattern matching, the compiler will issue a warning, and there will also be a warning for invalid items.
start ATM
-> current ATMSt: Ready
ins card
-> current ATMSt: CardInserted Z
checkPin 1
-> current ATMSt: CardInserted (S Z)
checkPin 2
-> current ATMSt: CardInserted (S (S Z))
checkPin 3
-> test 3 times, eject card!
-> current ATMSt: Ready
ins card
-> current ATMSt: CardInserted Z
checkPin 1234
-> current ATMSt: Session
getAmount
-> User Amount: 1000
-> current ATMSt: Session
dispense 100
-> Use dispense 100
-> Now User Amount: 900
-> current ATMSt: Session
dispense 100
-> Use dispense 100
-> Now User Amount: 800
-> current ATMSt: Session
eject
-> current ATMSt: Ready
I don’t quite follow McBride’s rationale (as often is the case) in haskell - What is indexed monad? - Stack Overflow , re. modeling an unpredictable (externally-driven) transition. Do you have some insight on this?