1    type TextPos = struct
2        line : u32
3        char : u32
4    
5        def compare (other : TextPos) = when
6            line < other.line -> Ordering/Less
7            line > other.line -> Ordering/Greater
8            char < other.char -> Ordering/Less
9            char > other.char -> Ordering/Greater
10           else -> Ordering/Equal
11   
12       is Compare
13   
14       def left = TextPos line (char - 1)
15       def right = TextPos line (char + 1)
16       def up = TextPos (line - 1) char
17       def down = TextPos (line + 1) char
18   
19       def min (other : TextPos) = when
20           line < other.line -> self@value
21           line > other.line -> other
22           char < other.char -> self@value
23           else -> other
24   
25       def max (other : TextPos) = when
26           line > other.line -> self@value
27           line < other.line -> other
28           char > other.char -> self@value
29           else -> other
30   
31       def to_string = "$line, $char"
32   
33   object TextPos =
34       val max = TextPos u32.max u32.max
35