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
|
-- Copyright © 2019 National Institute of Aerospace / Galois, Inc.
-- | Fault-tolerant voting examples.
{-# LANGUAGE RebindableSyntax #-}
module Main where
import Language.Copilot
vote :: Spec
vote = do
-- majority selects element with the biggest occurance.
trigger "maj" true [arg maj]
-- aMajority checks if the selected element has a majority.
trigger "aMaj" true [arg $ aMajority inputs maj]
where
maj = majority inputs
-- 26 input streams to vote on
inputs :: [Stream Word32]
inputs = [ a, b, c, d, e, f, g, h, i, j, k, l, m
, n, o, p, q, r, s, t, u, v, w, x, y, z
]
a = [0] ++ a + 1
b = [0] ++ b + 1
c = [0] ++ c + 1
d = [0] ++ d + 1
e = [1] ++ e + 1
f = [1] ++ f + 1
g = [1] ++ g + 1
h = [1] ++ h + 1
i = [1] ++ i + 1
j = [1] ++ j + 1
k = [1] ++ k + 1
l = [1] ++ l + 1
m = [1] ++ m + 1
n = [1] ++ n + 1
o = [1] ++ o + 1
p = [1] ++ p + 1
q = [1] ++ q + 1
r = [1] ++ r + 1
s = [1] ++ s + 1
t = [1] ++ t + 1
u = [1] ++ u + 1
v = [1] ++ v + 1
w = [1] ++ w + 1
x = [1] ++ x + 1
y = [1] ++ y + 1
z = [1] ++ z + 1
main :: IO ()
main = interpret 30 vote
|