package elm_playground_gamekits

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file Puzzle_undo.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(* Claude Code
 *
 * Copyright (C) 2026 Yoann Padioleau
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public License
 * (LGPL) as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 *)

(* See Puzzle_undo.mli *)

type 'a t = { now : 'a; past : 'a list }

let start (a : 'a) : 'a t = { now = a; past = [] }
let record (a : 'a) (h : 'a t) : 'a t = { now = a; past = h.now :: h.past }
let undo (h : 'a t) : 'a t = match h.past with before :: rest -> { now = before; past = rest } | [] -> h