176004af9f9027bd88ce60ca364252d6ee56f4c1
[minfp.git] / tests / preamble.mfp
1 //Function application
2 $ ifxr 0 x y = x y;
3 //Reverse function application
4 & ifxr 0 x y = y x;
5 //Composition
6 .. ifxr 9 f g x = f (g x);
7
8 //Arithmetic operators
9 == ifxl 7 = code eq;
10 * ifxl 7 = code mul;
11 - ifxl 6 = code sub;
12 + ifxl 6 = code add;
13 fst = code fst;
14 snd = code snd;
15
16 on f g a b = f (g a) (g b);
17
18 //Conditional operators
19 if = code if;
20
21 fac i = if (i == 0) 1 $ i * fac (i - 1);
22 id x = x;
23
24 even i = if (i == 0) True (odd (i - 1));
25 odd i = if (i == 0) False (even (i - 1));
26
27 uncurry f t = f (fst t) (snd t);
28
29 return a = \s. (a, s);
30 >>= ifxr 0 ma atmb = \s. uncurry atmb (ma s);
31
32 start = fst ((return 41 >>= \x. return (x + 1)) 4);