Last active
May 13, 2017 18:25
-
-
Save dungpa/46c48fdf25f73b34c7b428778d685613 to your computer and use it in GitHub Desktop.
Create a simple FSM model
This file contains hidden or 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
// A representation from http://stackoverflow.com/questions/5840292/automata-in-ocaml | |
type FiniteStateMachine<'State, 'Input> = { | |
Initial : 'State; | |
Final : 'State -> bool; | |
Transition : 'Input -> 'State -> 'State; | |
} | |
type IntegerKind = | |
| Odd | |
| Even | |
let odd = { | |
Initial = Even; | |
Final = (function Odd -> true | _ -> false); | |
Transition = (function | |
| "next" -> (function Even -> Odd | Odd -> Even) | |
| _ -> id); | |
} | |
let product a b = { | |
Initial = (a.Initial, b.Initial); | |
Final = (fun (x, y) -> a.Final x && b.Final y); | |
Transition = (fun c (x, y) -> a.Transition c x, b.Transition c y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment