-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprelude.cont
47 lines (33 loc) · 954 Bytes
/
prelude.cont
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
# prelude.cont
# this file is loaded before all the input files by the interpreter and contains basic
# definitions of standard library functions and types.
# this is the only file allowed to contain non-continuation-style top-level definitions.
type Bool = True | False;
type Maybe a = Just a | Nothing;
type Either e a = Left e | Right a;
type Pair a b = Pair a b;
a -> a ::
id x = x;
flip f x y = f y x;
Int -> Int ::
succ x = x + 1;
(b -> c) -> (a -> b) -> a -> c ::
comp f g x = f (g x);
(a -> b) -> [a] -> [b] ::
map f xs = match xs with
| [] => []
| h:t => f h : map f t;
a -> b -> a ::
const x _ = x;
(a -> b) -> a -> b -> a -> b ::
mapsTo f x y a =
if a == x
then y
else f a;
(a -> b) -> [a] -> [b] -> a -> b ::
multiMapsTo f xs ys = match Pair xs ys with
| Pair [] _ => f
| Pair _ [] => f
| Pair (x:xs) (y:ys) => multiMapsTo (mapsTo f x y) xs ys;
type Return a = Return a;
unReturn x = match x with | Return y => y;