-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchapter4-2-compose.rkt
47 lines (36 loc) · 925 Bytes
/
chapter4-2-compose.rkt
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
#lang pie
;; Define a function called compose that takes (in addition to the type
;; arguments A, B, C) an argument of type (-> A B) and an argument of
;; type (-> B C) that and evaluates to a value of type (-> A C), the function
;; composition of the arguments.
(claim compose
(Pi ((A U)
(B U)
(C U))
(-> (-> A B) (-> B C) (-> A C))))
(define compose
(lambda (A B C)
(lambda (f g)
(lambda (a)
(g (f a))))))
(claim iszero?
(-> Nat Atom))
(define iszero?
(lambda (n)
(rec-Nat n
'zero
(lambda (n-1 notzero)
'notzero))))
(claim twin
(-> Atom (Pair Atom Atom)))
(define twin
(lambda (a)
(cons a a)))
(claim double
(-> Nat (Pair Atom Atom)))
(define double
(compose Nat Atom (Pair Atom Atom) iszero? twin))
(check-same (Pair Atom Atom)
(double 0) (cons 'zero 'zero))
(check-same (Pair Atom Atom)
(double 100) (cons 'notzero 'notzero))