- Commit
- 09576bc799899f52dd768b2b459039ffa834715c
- Parent
- 923bc9ff2866f50ab9ecbc34453a41688a0b619a
- Author
- Pablo <pablo-escobar@riseup.net>
- Date
Removed type annotations from the implementation
A OCaml module for manipulating unlimited register machines
Removed type annotations from the implementation
1 file changed, 5 insertions, 5 deletions
Status | File Name | N° Changes | Insertions | Deletions |
Modified | urm.ml | 10 | 5 | 5 |
diff --git a/urm.ml b/urm.ml @@ -11,14 +11,14 @@ type machine = registers : nat -> nat; } -let from_registers (f : int -> int) : machine = +let from_registers f = { intruction_pointer = 0; registers = f } -let zero : machines = from_registers (fun _ -> 0) +let zero = from_registers (fun _ -> 0) -let register (m : machine) (i : int) : int = m.registers i +let register m = m.registers (** Executes the next instruction. Returns [Some _] is the instruction pointer points to a valid adress and [None] otherwise. *) @@ -48,12 +48,12 @@ let step (program : instruction array) (m : machine) : machine option = { m with instruction_pointer = m.instruction_pointer + 1 } in Some updated -let rec exec (program : instruction array) (m : machine) : machine = +let rec exec program m = match step program m with | None -> { m with instruction_pointer = 0 } | Some n -> exec program n -let exec_safe program (m : machine) (max : int) : machine option = +let exec_safe program m max = if max <= 0 then raise (Invalid_argument "the number of clock-cycles must be positive ") else