]> git.f4mnq.fr Git - cells.git/commitdiff
Inversion des arguments de ModeAndState (mode, puis état)
authorAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:38:52 +0000 (14:38 +0100)
committerAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:53:54 +0000 (14:53 +0100)
bin/main.ml
bin/modes.ml
bin/modes.mli

index 10efa2f9ac36f862c786adbeafbca78728378bbc..1dd33ac73bf7bfaf92ab2d1bdfdf85df40f7c8d7 100644 (file)
  *)
 
 let run (type state initer) (m : (module Modes.Mode with type state = state and type initer = initer)) (init : initer) =
-        let rec aux : type state. state -> (module Modes.Mode with type state = state) -> unit =
-               fun state m ->
+        let rec aux : type state. (module Modes.Mode with type state = state) -> state -> unit =
+               fun m state ->
                 let module M = (val m) in
                 M.render state;
                 Graphics.synchronize ();
                 if Graphics.key_pressed ()
                 then
                   match M.update state (Graphics.read_key ()) with
-                  | Either.Left state -> aux state m
-                  | Either.Right (ModeAndState (st, m)) -> aux st m
-                else aux state m
+                  | Either.Left state -> aux m state
+                  | Either.Right (ModeAndState (m, st)) -> aux m st
+                else aux m state
         in
         let module M = (val m) in
-        aux (M.initial init) (module M)
+        aux (module M) (M.initial init)
 
 let () =
         Graphics.open_graph "";
index a945fb8b4fca0274fba00087d4c5fcc819eefc54..02eeaaba0c20bddeed6b1d579577adb1d8eda3f2 100644 (file)
@@ -14,7 +14,7 @@
  *)
 
 module rec ModeAux : sig
-  type mode_and_state = ModeAndState : 'a * (module ModeAux.S with type state = 'a) -> mode_and_state
+  type mode_and_state = ModeAndState : (module ModeAux.S with type state = 'a) * 'a -> mode_and_state
 
   module type S = sig
     type state
@@ -51,7 +51,7 @@ module rec Command : (Mode with type initer = ModeAux.mode_and_state) = struct
           | "quit" ->
                   Graphics.close_graph ();
                   Either.right old
-          | "select" -> Either.right (ModeAux.ModeAndState (AutoSelector.initial (), (module AutoSelector)))
+          | "select" -> Either.right (ModeAux.ModeAndState ((module AutoSelector), AutoSelector.initial ()))
           | _ ->
                   Printf.fprintf stderr "Unknown cmd: `%s'\n%!" cmd;
                   Either.right old
@@ -122,7 +122,7 @@ functor
               | ':' ->
                       Either.right
                         (ModeAux.ModeAndState
-                           (Command.initial (ModeAux.ModeAndState (st, (module Impl))), (module Command)))
+                           ((module Command), Command.initial (ModeAux.ModeAndState ((module Impl), st))))
               | c when '0' <= c && c <= '9' -> Either.left (chnum (int_of_char c - int_of_char '0') st)
               | 's' -> Either.left (set_current st)
               | 'q' -> Either.left (ntimes (chcur M.prev) st)
@@ -185,7 +185,7 @@ and AutoSelector : (Mode with type initer = unit) = struct
           | 's' ->
                   let module M = (val curr : Automata.Automaton) in
                   let module NormalM = Normal (M) in
-                  Either.right (ModeAux.ModeAndState (NormalM.initial (), (module NormalM)))
+                  Either.right (ModeAux.ModeAndState ((module NormalM), NormalM.initial ()))
           | 'q' ->
                   Graphics.close_graph ();
                   Either.left (above, curr, below)
index dff6877eb772840678bae4c84c0770bef87ed1bc..202e93d0e71c7937923b896679430b2ea1256347 100644 (file)
@@ -14,7 +14,7 @@
  *)
 
 module rec ModeAux : sig
-  type mode_and_state = ModeAndState : 'a * (module ModeAux.S with type state = 'a) -> mode_and_state
+  type mode_and_state = ModeAndState : (module ModeAux.S with type state = 'a) * 'a -> mode_and_state
 
   module type S = sig
     type state