Files
  • main.py
main.py
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
def succ(n):
    return n + 1

def pred(n):
    return n - 1

def double(n):
    return n * 2

def triple(n):
    return n * 3
  
def add(x,y):
    return x + y

def add5(x):
    return add(5,x)

# before running the following, guess what the output should be: 
# higher(succ, double, min)
# higher(pred, max, add)
# higher(lambda x: x + 5, lambda x: 5 * x, max)
# higher(pred, triple, lambda x,y: 2 * x * y )
def higher(x, y, z):
    return x(10) + y(20) + z(3,4)


def adder(c):
    def addtmp(x):
        return x + c
    return addtmp

def compose(f,g):
    def tmp(a):
        return f(g(a))
    return tmp

def composeAnon(f,g):
    return lambda x: f(g(x))
    
f = add

def F(x):
    def tmp(y):
        return f(x,y)
    return tmp
    
def Fanon(x):
  return lambda y: f(x,y)