-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathed_defs.v
22 lines (17 loc) · 855 Bytes
/
ed_defs.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Require Import Coq.Lists.List.
Inductive Command {X : Type} : Type :=
| ReadLine : nat -> X -> Command
| InsertLine : nat -> X -> Command
| DeleteLine : nat -> X -> Command.
Definition readLine {X : Type} (buffer : list X) (pos : nat) (d : X) : X :=
nth pos buffer d.
Definition insertLine {X : Type} (buffer : list X) (pos : nat) (s : X) : (list X) :=
firstn pos buffer ++ s :: nil ++ skipn pos buffer.
Definition deleteLine {X : Type} (buffer : list X) (pos : nat) : (list X) :=
firstn pos buffer ++ skipn (pos + 1) buffer.
Definition EditorEval {X : Type} (cmd : @Command X) (buffer : list X) : (list X * X) :=
match cmd with
| ReadLine pos d => pair buffer (readLine buffer pos d)
| InsertLine pos s => pair (insertLine buffer pos s) s
| DeleteLine pos d => pair (deleteLine buffer pos) (readLine buffer pos d)
end.