-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBits.fm
More file actions
59 lines (51 loc) · 1.3 KB
/
Copy pathBits.fm
File metadata and controls
59 lines (51 loc) · 1.3 KB
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
58
59
T Bits
| Bits.nil;
| Bits.0(pred: Bits);
| Bits.1(pred: Bits);
Bits.concat(a: Bits, b: Bits): Bits
case a:
| b;
| Bits.0(Bits.concat(a.pred, b));
| Bits.1(Bits.concat(a.pred, b));
Bits.eql(a: Bits, b: Bits): Bool
case a:
| case b:
| Bool.true;
| Bool.false;
| Bool.false;;
| case b:
| Bool.false;
| Bits.eql(a.pred, b.pred);
| Bool.false;;
| case b:
| Bool.false;
| Bool.false;
| Bits.eql(a.pred, b.pred);;
Bits.from_string(str: String): Bits
case str:
| Bits.nil;
| case U16.eql(str.head, Char.parse("1")):
| Bits.1(Bits.from_string(str.tail));
| Bits.0(Bits.from_string(str.tail));
| Unit.new;;
Bits.inc(a: Bits): Bits
case a:
| Bits.nil;
| Bits.1(a.pred);
| Bits.0(Bits.inc(a.pred));
Bits.parse_hex: String -> Bits
(str) Bits.parse_hex.tco(str)(Bits.nil)
Bits.parse_hex.tco(str: String, res: Bits): Bits
case str:
| res;
| let b0000 = Bits.0(Bits.0(Bits.0(Bits.0(Bits.nil))))
let bhead = Nat.apply<Bits>(Char.hex_value(str.head), Bits.inc, b0000)
Bits.parse_hex.tco(str.tail, Bits.concat(bhead, res));
// Reverses a bistring.
Bits.reverse(a: Bits): Bits
Bits.reverse.tco(a, Bits.nil)
Bits.reverse.tco(a: Bits, r: Bits): Bits
case a:
| r;
| Bits.reverse.tco(a.pred, Bits.0(r));
| Bits.reverse.tco(a.pred, Bits.1(r));