projects
/
ghc-hetmet.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
extra prettyprinting only when debugging
[ghc-hetmet.git]
/
compiler
/
ilxGen
/
tests
/
test4.hs
1
class Eqq a where
2
evenN :: a -> Bool
3
oddN :: a -> Bool
4
evenN x = False
5
oddN x = True
6
7
8
data N = Z | S N
9
10
instance Eqq N
11
where
12
evenN Z = True
13
evenN (S x) = oddN x
14
oddN Z = False
15
oddN (S x) = evenN x
16
17
choose x = if evenN x then "hello world (evenN)\n" else if oddN x then "hello world (oddN)\n" else "no!\n"
18
19
add n m =
20
case n of
21
Z -> m
22
S nn -> S (add nn m)
23
24
mul n m =
25
case n of
26
Z -> Z
27
S nn -> add m (mul nn m)
28
29
pow n m =
30
case m of
31
Z -> S Z
32
S mm -> mul n (pow n mm)
33
34
n1 = S Z
35
n2 = add n1 n1
36
n4 = add n2 n2
37
n6 = add n2 n4
38
n8 = add n2 n6
39
n10 = add n2 n8
40
n16 = add n6 n10
41
n18 = add n8 n10
42
n20 = add n4 n16
43
44
bign = pow n2 n16
45
bign1 = add bign n1
46
47
main = putStr (choose bign1)