-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExHyper.hs
59 lines (41 loc) · 1.08 KB
/
ExHyper.hs
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
module ExHyper where
import Prelude hiding ( exp )
-- Nat datatype --------------------------------
data Nat = Z | S Nat
deriving (Eq, Show)
instance (Num Nat) where
(+) = add
(*) = mul
abs = id
fromInteger 0 = Z
fromInteger n
| n > 0 = S $ fromInteger (n-1)
| otherwise = Z
signum Z = Z
signum n = S Z
negate n = Z
instance (Ord Nat) where
Z <= m = True
(S n) <= Z = False
(S n) <= (S m) = n <= m
{- explicit definitions of add, mul, exp:
add n Z = n
add n (S m) = S (add m n)
mul n Z = Z
mul n (S m) = add (mul n m) n
exp n Z = S Z
exp n (S m) = mul (exp n m) n
-}
------------------------------------------------
-- substitute 'undefined' by the correct number
-- to define each of those functions:
add :: Nat -> Nat -> Nat
add = hyper undefined
mul :: Nat -> Nat -> Nat
mul = hyper undefined
exp :: Nat -> Nat -> Nat
exp = hyper undefined
-- hyper n should return the n'th operation in the sequence:
-- (..?..), add, mul, exp, ...?
hyper :: Integral i => i -> (Nat -> Nat -> Nat)
hyper = undefined