From 055c743c55bde27f4475d3434c26d8383c0c3ea1 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Thu, 11 Jan 2024 19:31:31 +0100 Subject: bulk: add PoC of vim-like modular editor --- lib/modes.ml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/modes.ml (limited to 'lib/modes.ml') diff --git a/lib/modes.ml b/lib/modes.ml new file mode 100644 index 0000000..3d0e354 --- /dev/null +++ b/lib/modes.ml @@ -0,0 +1,18 @@ +type mode = Normal | Insert +type t = mode +type state = int +type 'a state_monad = state -> 'a * state + +let run (f : 'a state_monad) (s : state) : 'a = f s |> fst +let return (a : 'a) : 'a state_monad = fun s -> (a, s) + +let ( >>= ) (f : 'a state_monad) (g : 'a -> 'b state_monad) : 'b state_monad = + fun s -> + let a, s' = f s in + g a s' + +let draw () : unit state_monad = return () +let get_keypress () : char state_monad = return 'a' +let handle_key (_ : char) : unit state_monad = return () +let rec loop () = () |> draw >>= get_keypress >>= handle_key >>= loop +let test = run (loop ()) 0 -- cgit v1.2.3