-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku-types.sml
57 lines (48 loc) · 1.46 KB
/
sudoku-types.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
(* terminology:
* - cell : can be empty, or have value 1-9
* - row : the row of three cells
* - square: three rows, total of nine cells
* - board : nine squares, 3 x 3
*
* - field : specialization of a generic square with cells
* - board : specialization of a generic square with fields?
*)
signature SUDOKU_TYPES =
sig
(* datatype value = One | Two | Three | Four | Five | Six | Seven | Eight | Nine *)
(* datatype cell = Empty | Val of value *)
type value
type cell
type board
val to_value : string -> cell
val to_str : cell -> string
exception UnsupportedValue of string
end
structure SudokuTypes : SUDOKU_TYPES =
struct
datatype value = One | Two | Three | Four | Five | Six | Seven | Eight | Nine
datatype cell = Empty | Val of value
type board = cell list list
exception UnsupportedValue of string
fun to_value "1" = Val One
| to_value "2" = Val Two
| to_value "3" = Val Three
| to_value "4" = Val Four
| to_value "5" = Val Five
| to_value "6" = Val Six
| to_value "7" = Val Seven
| to_value "8" = Val Eight
| to_value "9" = Val Nine
| to_value ("x" | "-" | ".") = Empty
| to_value x = raise UnsupportedValue x
fun to_str (Val One) = "1"
| to_str (Val Two) = "2"
| to_str (Val Three) = "3"
| to_str (Val Four) = "4"
| to_str (Val Five) = "5"
| to_str (Val Six) = "6"
| to_str (Val Seven) = "7"
| to_str (Val Eight) = "8"
| to_str (Val Nine) = "9"
| to_str Empty = "-"
end