blob: c4b2336df1eb7759a4e228c615955168ad0ca215 (
plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
-- To start:
-- source /bin/devghc
-- To compile GHC
-- make ilxGen/IlxGen.o hsc
-- To compile ILXASM
-- (cd /devel/fcom/src; make bin/ilxasm.exe)
-- To compile to ILX
-- (cd ilxGen/tests; ../../../driver/ghc-inplace --ilx test.hs)
-- To generate a complete ILX file, including preludes for GHC and ILX:
-- (cd ilxGen/tests/; cat prelude.ilx test.ilx /devel/fcom/src/ilxasm/stdlib-func.ilx > test.full.ilx)
-- Run ILXASM to get a IL
-- ( cd ilxGen/tests/; /devel/fcom/src/bin/ilxasm.exe --no-ilasm --no-stdlib test.full.ilx > test.il)
-- To compile IL to .EXE or .DLL:
-- With build of VS (e.g. Don & Andrew)
-- ( cd ilxGen/tests/; cmd /C "c:\\bin\\devvs.bat && ilasm test.il")
-- With Lightning SDK, where env. variables are on path (e.g. Reuben):
-- ( cd ilxGen/tests/; ilasm test.il)
-- To validate .EXE:
-- (cd /devel/fcom/src; make bin/ilvalid.exe mscorlib.vlb)
-- (export ILVALID_HOME=/devel/fcom/src; cd ilxGen/tests/; /devel/fcom/src/bin/ilvalid.exe test.il)
-- To run unverifiable code:
-- With build of VS (e.g. Don & Andrew)
-- (cd ilxGen/tests/; cmd /C "c:\\bin\\devvs.bat && .\test.exe")
-- With Lightning SDK, where env. variables are on path (e.g. Reuben):
-- (cd ilxGen/tests/; ./test.exe)
-- To compile ILX to verifiable code and verify
-- (cd /devel/fcom/src; make bin/ilxasm.exe bin/ilverify.exe) && (cd ilxGen/tests/; export ILVALID_HOME=/devel/fcom/src; cat prelude.ilx test.ilx /devel/fcom/src/assem/stdlib-func.ilx > test.full.ilx && cd ilxGen/tests/; /devel/fcom/src/bin/ilxasm.exe --no-ilasm test.full.ilx > test.safe.il && /devel/fcom/src/bin/ilverify.exe test.safe.il)
-- (cd ilxGen/tests/; cmd /C "c:\\bin\\devvs.bat && .\test.safe.exe")
--append:: [Char] -> [Char] -> [Char]
--append [] l2 = l2
--append (h:t) l2 = h:append t l2
data N = Z | S N
chooseN n =
case n of
Z -> "even\n"
S Z -> "odd\n"
S (S m) -> chooseN m
signN n =
case n of
Z -> Z
S Z -> S Z
S (S m) -> signN m
add n m =
case n of
Z -> m
S nn -> S (add nn m)
mul n m =
case n of
Z -> Z
S nn -> add m (mul nn m)
pow n m =
case m of
Z -> S Z
S mm -> mul n (pow n mm)
sq n = mul n n
n1 = S Z
n2 = add n1 n1
n4 = add n2 n2
n6 = add n2 n4
n8 = add n2 n6
n10 = add n2 n8
n11 = add n1 n10
n12 = add n1 n11
n13 = add n1 n12
n14 = add n1 n13
n15 = add n1 n14
n16 = add n1 n15
n17 = add n1 n16
n18 = add n1 n17
n19 = add n1 n18
n20 = add n1 n18
bign = pow n2 n19
bign1 = add bign n1
foldn f n acc =
case n of
Z -> acc
S x -> foldn f x (f n acc)
main = putStr (chooseN (foldn (\x y -> add (signN x) y) (pow n2 n4) n1))
|