summaryrefslogtreecommitdiff
path: root/lib/modes.ml
diff options
context:
space:
mode:
authorFederico Igne <undyamon@disroot.org>2024-01-11 19:31:31 +0100
committerFederico Igne <undyamon@disroot.org>2024-01-11 19:31:31 +0100
commit055c743c55bde27f4475d3434c26d8383c0c3ea1 (patch)
treeaabf2173a9995f5795da86d5676181b62fee0e9e /lib/modes.ml
parent416c56656af65d656f637dc8c8fdb62d0ba03e29 (diff)
downloadsandy-055c743c55bde27f4475d3434c26d8383c0c3ea1.tar.gz
sandy-055c743c55bde27f4475d3434c26d8383c0c3ea1.zip
bulk: add PoC of vim-like modular editor
Diffstat (limited to 'lib/modes.ml')
-rw-r--r--lib/modes.ml18
1 files changed, 18 insertions, 0 deletions
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 @@
1type mode = Normal | Insert
2type t = mode
3type state = int
4type 'a state_monad = state -> 'a * state
5
6let run (f : 'a state_monad) (s : state) : 'a = f s |> fst
7let return (a : 'a) : 'a state_monad = fun s -> (a, s)
8
9let ( >>= ) (f : 'a state_monad) (g : 'a -> 'b state_monad) : 'b state_monad =
10 fun s ->
11 let a, s' = f s in
12 g a s'
13
14let draw () : unit state_monad = return ()
15let get_keypress () : char state_monad = return 'a'
16let handle_key (_ : char) : unit state_monad = return ()
17let rec loop () = () |> draw >>= get_keypress >>= handle_key >>= loop
18let test = run (loop ()) 0