Skip to content

Commit 775d5e7

Browse files
committed
letrec tests
1 parent 1afd8f1 commit 775d5e7

File tree

6 files changed

+79
-0
lines changed

6 files changed

+79
-0
lines changed

tests/succeed/letrec/factorial.fathom

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// FIXME: using (x - 1) causes a crash in distillation
2+
3+
letrec
4+
factorial : U32 -> U32
5+
= fun (x : U32) => match x {
6+
0 => 1,
7+
_ => x * factorial (u32_sub x 1),
8+
},
9+
factorial_iter : U32 -> U32 -> U32
10+
= fun (acc: U32) (x : U32) => match x {
11+
0 => acc,
12+
_ => factorial_iter (acc * x) (u32_sub x 1),
13+
};
14+
(factorial, factorial_iter)

tests/succeed/letrec/factorial.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
stdout = '''
2+
letrec
3+
factorial : U32 -> U32 = fun x => match x {
4+
0 => 1,
5+
_ => x * factorial (x - (1 : U32)),
6+
},
7+
factorial_iter : U32 -> U32 -> U32 = fun acc x => match x {
8+
0 => acc,
9+
_ => factorial_iter (acc * x) (x - (1 : U32)),
10+
},
11+
;
12+
(factorial, factorial_iter) : (U32 -> U32, U32 -> U32 -> U32)
13+
'''
14+
stderr = ''

tests/succeed/letrec/fibonacci.fathom

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// FIXME: using (x - 1) or (x - 2) causes crash during distillation
2+
3+
letrec
4+
fibonacci : U32 -> U32
5+
= fun (x : U32) => match x {
6+
0 => 0,
7+
1 => 1,
8+
_ => (fibonacci (u32_sub x 1)) + (fibonacci (u32_sub x 2)),
9+
};
10+
fibonacci

tests/succeed/letrec/fibonacci.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
stdout = '''
2+
letrec
3+
fibonacci : U32 -> U32 = fun x => match x {
4+
0 => 0,
5+
1 => 1,
6+
_ => fibonacci (x - (1 : U32)) + fibonacci (x - (2 : U32)),
7+
},
8+
;
9+
fibonacci : U32 -> U32
10+
'''
11+
stderr = ''

tests/succeed/letrec/parity.fathom

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// FIXME: using (x - 1) causes crash during distillation
2+
3+
letrec
4+
is_even : U32 -> Bool
5+
= fun (x : U32) => match x {
6+
0 => true,
7+
_ => is_odd (u32_sub x 1),
8+
},
9+
10+
is_odd : U32 -> Bool
11+
= fun (x : U32) => match x {
12+
0 => false,
13+
_ => is_even (u32_sub x 1),
14+
},
15+
;
16+
(is_even, is_odd)

tests/succeed/letrec/parity.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
stdout = '''
2+
letrec
3+
is_even : U32 -> Bool = fun x => match x {
4+
0 => true,
5+
_ => is_odd (x - (1 : U32)),
6+
},
7+
is_odd : U32 -> Bool = fun x => match x {
8+
0 => false,
9+
_ => is_even (x - (1 : U32)),
10+
},
11+
;
12+
(is_even, is_odd) : (U32 -> Bool, U32 -> Bool)
13+
'''
14+
stderr = ''

0 commit comments

Comments
 (0)