-
Notifications
You must be signed in to change notification settings - Fork 0
/
collatz.expc
62 lines (48 loc) · 1.16 KB
/
collatz.expc
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
60
61
62
haskell {
(>>>) :: Bits a => a -> Int -> a
(>>>) = shiftR
(<<<) :: Bits a => a -> Int -> a
(<<<) = shiftL
type Value = Unsigned 16
}
component router() {
input val : Value
output odd : Maybe Value
output even : Maybe Value
even = if testBit val 0 then Nothing else Just val
odd = if testBit val 0 then Just val else Nothing
}
component onEven() {
input val : Maybe Value
output res : Maybe Value
res = case val of
Just v -> Just $ v >>> 1
Nothing -> Nothing
}
component onOdd() {
input val : Maybe Value
output res : Maybe Value
res = case val of
Just v -> Just $ (v <<< 1 + v) + 1
Nothing -> Nothing
}
component merger() {
input vo : Maybe Value
input ve : Maybe Value
output res : Value
res = case vo of
Just v -> v
Nothing -> case ve of
Just v -> v
Nothing -> 0
}
component control() {
input next_val : Value
input set_val : Maybe Value
state last_val = 0 : Value
output result_value : Value
last_val' = case set_val of
Just new_value -> new_value
Nothing -> next_val
result_value = last_val
}