-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype-tests.scm
42 lines (36 loc) · 953 Bytes
/
type-tests.scm
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
;
;test case 1
;
(check-type
(type-lambda ('a)
(lambda ([xs : (list (list 'a))])
((@ car 'a) ((@ car (list 'a)) xs))))
(forall ('a) ((list (list 'a)) -> 'a)))
;;
;; test case 2
;;
(val-rec
(forall ('a) (int (list 'a) -> (list 'a)))
take
(type-lambda ['a]
(lambda ([n : int] [xs : (list 'a)])
(if ((@ null? 'a) xs)
(@ '() 'a)
(if (> n 0)
((@ cons 'a) ((@ car 'a) xs) ((@ take 'a) (- n 1) ((@ cdr 'a) xs)))
(@ '() 'a))))))
(check-type take (forall ('a) (int (list 'a) -> (list 'a))))
;;
;; test case 3
;;
(val-rec
(forall ('a) (('a -> bool) (list 'a) -> (list 'a)))
dropwhile
(type-lambda ['a]
(lambda ([p? : ('a -> bool)] [xs : (list 'a)])
(if ((@ null? 'a) xs)
(@ '() 'a)
(if (p? ((@ car 'a) xs))
((@ dropwhile 'a) p? ((@ cdr 'a) xs))
xs)))))
(check-type dropwhile (forall ('a) (('a -> bool) (list 'a) -> (list 'a))))