Create executable from finite state automaton

Is it possible to produce an executable with ocamlc or ocamlopt that acts as an optimized task manager for a small list of tasks, featuring 1) autocompletion
and 2) reacting to keystrokes without having to type “ENTER” ?

Say I have the following :

type state
val transition : state → char → state
val action : state → char → unit

From those initial data, what code should I write to have my executable start in state 0 when launched, and everytime a key corresponding to character c is pressed and the executable is in state i, I want it to execute action(i,c) and go to state transition(i,c).

I found a lot of material mildly related to this, but nothing dealing with it directly. For example, I know that utop has autocompletion, but I don’t want to spend a lot of time learning about utop’s internals.

utop is built using lambda-term

The source code of lambda-term comes with an example of REPL, which can be quite easily adapted.

2 Likes

How is autocomplete supposed to work? Based on the current state, what should it do? And what about the actions during autocomplete? Based on the interface, there is no way to know which transitions are legal from a state and hence no way to “complete” to another state.

Looks like what I need, I’ll try it, thanks a lot.

I didn’t elaborate on that because I didn’t need to, and I wanted to keep my question simple and short. But since you ask, here are more specific details : I want to combine autocompletion pretty much as it exists in utop (except that I want uncapitalized module names which I find more natural), combined with a few commands to recompile a module, rename a module, duplicate a module, etc.

Today, about a year later (better late than never!), I just realized that you can get most of the REPL functionality using only Ocaml’s builtin read_line function in the toplevel.