Merge branch 'master' of gaufre.informatique.univ-paris-diderot.fr:aguatto/compilation-m1-2023

This commit is contained in:
Mylloon 2023-12-11 12:56:35 +01:00
commit c2cdce8baa
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
27 changed files with 136 additions and 2 deletions

Binary file not shown.

View file

@ -0,0 +1 @@
120

View file

@ -0,0 +1,5 @@
fun fact (n) =
if n =? 0 then 1 else n * fact (n - 1) fi
val main =
print_int (fact (5))

View file

@ -0,0 +1 @@
42

View file

@ -0,0 +1,5 @@
fun addk (k) = \(x) => x + k
val f = addk (41)
val main = print_int (f (1))

View file

@ -0,0 +1 @@
42

View file

@ -0,0 +1,3 @@
fun apply (f, x) = f (x)
val main = apply ((\(x) => print_int (x)), 42)

View file

@ -0,0 +1 @@
42

View file

@ -0,0 +1,10 @@
val curry =
\(f) => \(x) => \(y) => f (x, y)
val add = \(x, y) => x + y
val g = curry (add)
val h = g (1)
val main = print_int (h (41))

View file

@ -0,0 +1 @@
1

View file

@ -0,0 +1,10 @@
fun f (x) =
if x =? 0 then 1
else g (x - 1)
fi
and g (x) =
if x =? 0 then 0
else f (x - 1)
fi
val main = print_int (f (20))

View file

@ -0,0 +1 @@
42424240

View file

@ -0,0 +1,12 @@
fun compose (f, g) =
\(x) => f (g (x))
fun id (x) = x
fun twice (x) = 2 * x
val main =
print_int (twice (21));
print_int (compose (id, twice) (21));
print_int (compose (twice, id) (21));
print_int (compose (twice, twice) (10))

View file

@ -0,0 +1 @@
42

View file

@ -0,0 +1,7 @@
val f = \(z) =>
val x = z + 1;
val y = x;
val t = 0;
\(k) => k + x
val main = print_int (f (21) (20))

View file

@ -0,0 +1,9 @@
val f = \(z) =>
val x = z + 1;
val y = x;
val t = 0;
fun g (x) = f(y + x, x)
and f (a, b) = z + a;
\(k) => g (k) + x
val main = print_int (f (21) (20))

View file

@ -0,0 +1 @@
3610152136101521

View file

@ -0,0 +1,29 @@
val curry_1_2 = \(f) => \(x) => \(y) => f (x, y)
val curry_1_3 = \(f) => \(x) => \(y1, y2) => f (x, y1, y2)
val curry_1_4 = \(f) => \(x) => \(y1, y2, y3) => f (x, y1, y2, y3)
val curry_1_5 = \(f) => \(x) => \(y1, y2, y3, y4) => f (x, y1, y2, y3, y4)
val curry_1_6 = \(f) => \(x) => \(y1, y2, y3, y4, y5) => f (x, y1, y2, y3, y4, y5)
val f2 = \(x1, x2) => x1 + x2
val f3 = \(x1, x2, x3) => x1 + x2 + x3
val f4 = \(x1, x2, x3, x4) => x1 + x2 + x3 + x4
val f5 = \(x1, x2, x3, x4, x5) => x1 + x2 + x3 + x4 + x5
val f6 = \(x1, x2, x3, x4, x5, x6) => x1 + x2 + x3 + x4 + x5 + x6
val test1_2 = print_int (curry_1_2 (f2) (1) (2))
val test1_3 = print_int (curry_1_3 (f3) (1) (2, 3))
val test1_4 = print_int (curry_1_4 (f4) (1) (2, 3, 4))
val test1_5 = print_int (curry_1_5 (f5) (1) (2, 3, 4, 5))
val test1_6 = print_int (curry_1_6 (f6) (1) (2, 3, 4, 5, 6))
val curry_2_2 = \(f) => \(o, x) => \(y) => f (x, y)
val curry_2_3 = \(f) => \(o, x) => \(y1, y2) => f (x, y1, y2)
val curry_2_4 = \(f) => \(o, x) => \(y1, y2, y3) => f (x, y1, y2, y3)
val curry_2_5 = \(f) => \(o, x) => \(y1, y2, y3, y4) => f (x, y1, y2, y3, y4)
val curry_2_6 = \(f) => \(o, x) => \(y1, y2, y3, y4, y5) => f (x, y1, y2, y3, y4, y5)
val test2_2 = print_int (curry_2_2 (f2) (0, 1) (2))
val test2_3 = print_int (curry_2_3 (f3) (0, 1) (2, 3))
val test2_4 = print_int (curry_2_4 (f4) (0, 1) (2, 3, 4))
val test2_5 = print_int (curry_2_5 (f5) (0, 1) (2, 3, 4, 5))
val test2_6 = print_int (curry_2_6 (f6) (0, 1) (2, 3, 4, 5, 6))

View file

@ -0,0 +1 @@
18

View file

@ -0,0 +1,9 @@
val f = \(x) =>
val g = \(y) =>
(val h = \(z) =>
(val i = \(t) => x + y + z + t;
i (z + 1));
h (y + 1));
g (x + 1)
val main = print_int (f (3))

View file

@ -0,0 +1 @@
4233

View file

@ -0,0 +1,7 @@
fun apply (f, x) = f (x)
fun apply2 (f, x, y) = f (x, y)
val main =
apply (print_int, 42);
apply (print_int, (apply2 (`+`, 31, 2)))

View file

@ -0,0 +1 @@
2042

View file

@ -0,0 +1,14 @@
fun h (x, y, z) =
fun f (x) =
if x =? 0 then z
else g (x - 1)
fi
and g (x) =
if x =? 0 then y
else f (x - 1)
fi;
g (x)
val main =
print_int (h (2, 20, 42));
print_int (h (3, 20, 42))

View file

@ -3,8 +3,10 @@ JALONS=\
01-Parsing.results \
01-Parsing-no-positions.results \
02-Interpreter.results \
03-Typing.results
EXTS=parsing.hopix parsing-no-positions.hopix eval.hopix typing.hopix
03-Typing.results \
04-Hobix_to_Fopix.results
EXTS=parsing.hopix parsing-no-positions.hopix eval.hopix typing.hopix \
hobix
.PHONY: all clean test FAKE
.PRECIOUS: %.output %.expected %.score