strictness, ci
[minfp.git] / tests / preamble.mfp
1 :: List a = Nil | Cons a (List a);
2 :: Tuple a b = Tuple a b;
3 :: Either a b = Left a | Right b;
4 :: Maybe a = Nothing | Just a;
5 :: St s a = St (s -> Tuple a s);
6
7 //Function application
8 $ ifxr 0 x y = x y;
9 //Reverse function application
10 & ifxr 0 x y = y x;
11 //Flip
12 flip f x y = f y x;
13 //Composition
14 .. ifxr 9 f g x = f (g x);
15
16 //Arithmetic operators
17 == ifxl 7 = code eq;
18 * ifxl 7 = code mul;
19 - ifxl 6 = code sub;
20 + ifxl 6 = code add;
21 //fst = code fst;
22 //snd = code snd;
23
24 on f g a b = f (g a) (g b);
25
26 //Conditional operators
27 if = code if;
28
29 fac i = if (i == 0) 1 $ i * fac (i - 1);
30 id x = x;
31
32 even i = if (i == 0) True (odd (i - 1));
33 odd i = if (i == 0) False (even (i - 1));
34
35 //uncurry f t = f (fst t) (snd t);
36
37 return a = St $ Tuple a;
38 //>>= ifxr 0 ma atmb = \s. uncurry atmb (ma s);
39
40 start = St;