Skip to content

Commit 0fd3c7e

Browse files
committed
Add open recursion article
1 parent 05d513c commit 0fd3c7e

File tree

7 files changed

+1007
-8
lines changed

7 files changed

+1007
-8
lines changed

GNUmakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pretty:
2+
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web openrecursion.fdoc
23
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web embedc.fdoc
34
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web corout.fdoc
45
env DYLD_LIBRARY_PATH=${LD_LIBRARY_PATH} flx_pretty --outdir=web views.fdoc
@@ -22,6 +23,7 @@ packages:
2223
extract:
2324
flx_iscr embedc.fdoc
2425
flx_iscr corout.fdoc
26+
flx_iscr openrecursion.fdoc
2527

2628

2729
test:

corout.fdoc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
@tangler ex1 = examples/ex1.flx
2-
@tangler ex2 = examples/ex2.flx
3-
@tangler ex3 = examples/ex3.flx
4-
@tangler ex4 = examples/ex4.flx
5-
@tangler ex5 = examples/ex5.flx
1+
@tangler ex1 = examples/corout/ex1.flx
2+
@tangler ex2 = examples/corout/ex2.flx
3+
@tangler ex3 = examples/corout/ex3.flx
4+
@tangler ex4 = examples/corout/ex4.flx
5+
@tangler ex5 = examples/corout/ex5.flx
6+
@tangler ex6 = examples/corout/ex6.fx
67
@title coroutines
78
@h1 A low level example.
89
I will show a simple low level example of coroutines, it will be a

examples/openrecursion/openrec.flx

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#line 69 "openrecursion.fdoc"
2+
typedef o_adde[T] = (
3+
| `Int of int
4+
| `Add of T * T
5+
);
6+
#line 79 "openrecursion.fdoc"
7+
fun o_eval[T] (eval: T -> int) (term: o_adde[T]) =>
8+
match term with
9+
| `Int j => j
10+
| `Add (a,b) => eval a + eval b
11+
endmatch
12+
;
13+
#line 91 "openrecursion.fdoc"
14+
typedef adde = o_adde[adde];
15+
fun eval (term:adde):int => o_eval[adde] eval term;
16+
#line 103 "openrecursion.fdoc"
17+
var x : adde = `Add (`Add (`Int 39, `Int 2), `Int 1);
18+
var y = eval x;
19+
println$ y;
20+
#line 113 "openrecursion.fdoc"
21+
typedef o_sube[T] = (
22+
| o_adde[T]
23+
| `Sub of T * T
24+
);
25+
fun o_eval2[T] (eval: T -> int) (term: o_sube[T]):int =>
26+
match term with
27+
| `Sub (a,b) => eval a - eval b
28+
| o_adde[T] :>> k => o_eval eval k
29+
endmatch
30+
;
31+
#line 139 "openrecursion.fdoc"
32+
typefun o_sube_f (T:TYPE) : TYPE => o_sube[T];
33+
typedef sube = tfix<TYPE> o_sube_f;
34+
fun eval2 (term:sube):int => (fix[sube,int] o_eval2[sube]) term;
35+
#line 160 "openrecursion.fdoc"
36+
var x2 : sube = `Add (`Sub (`Int 39, `Int 2), `Int 1);
37+
var y2 = eval2 x2;
38+
var y3 = eval2 x; // ORGINAL DATA
39+
println$ y2;
40+
println$ y3;
41+
#line 187 "openrecursion.fdoc"
42+
typedef o_mule[T] = (
43+
| o_adde[T]
44+
| `Mul of T * T
45+
);
46+
fun o_eval3[T] (eval: T -> int) (term: o_mule[T]):int =>
47+
match term with
48+
| `Mul(a,b) => eval a * eval b
49+
| o_adde[T] :>> k => o_eval eval k
50+
endmatch
51+
;
52+
typefun o_mule_f (T:TYPE) : TYPE => o_mule[T];
53+
typedef mule = tfix<TYPE> o_mule_f;
54+
fun eval3 (term:mule):int => (fix[mule,int] o_eval3[mule]) term;
55+
var x3 : mule = `Add (`Mul(`Int 39, `Int 2), `Int 1);
56+
var y4 = eval3 x3;
57+
var y5 = eval3 x; // ORGINAL DATA
58+
println$ y4;
59+
println$ y5;
60+
#line 211 "openrecursion.fdoc"
61+
typedef o_dive[T] = (
62+
| o_sube[T]
63+
| o_mule[T]
64+
| `Div of T * T
65+
);
66+
fun o_eval4[T] (eval: T -> int) (term: o_dive[T]):int =>
67+
match term with
68+
| `Div(a,b) => eval a / eval b
69+
| o_sube[T] :>> k => o_eval2 eval k
70+
| o_mule[T] :>> k => o_eval3 eval k
71+
endmatch
72+
;
73+
typefun o_dive_f (T:TYPE) : TYPE => o_dive[T];
74+
typedef dive = tfix<TYPE> o_dive_f;
75+
fun eval4 (term:dive):int => (fix[dive,int] o_eval4[dive]) term;
76+
var x4 : dive =
77+
`Add (
78+
`Mul (
79+
`Int 39,
80+
`Sub (
81+
`Int 3,
82+
`Div (`Int 2, `Int 2)
83+
)
84+
)
85+
,
86+
`Int 66
87+
)
88+
;
89+
var y6 = eval4 x4;
90+
var y7 = eval4 x; // ORGINAL DATA
91+
var y8 = eval4 x2; // ORGINAL DATA
92+
var y9 = eval4 x3; // ORGINAL DATA
93+
println$ y6;
94+
println$ y7;
95+
println$ y8;
96+
println$ y9;

index.html

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
</style>
3939

4040
<body>
41-
<h1>Felix programming system.</h1>
41+
<h1 style="text-align:center">Felix programming system.</h1>
42+
<img src="share/src/web/images/FelixWork.jpg" style="width:200px;position:absolute:top:200px;left:10px">
43+
<div style="position:absolute;left:250px;top:50px;width:50%">
4244
<pre class='flxbg'>
4345
<span class="lineno" id=line1></span> <span class="library" title="Print a string to standard output with newline appended">println</span>$ <span class="fstring">"Hello World!"</span>;
4446
</pre>
@@ -47,15 +49,51 @@ <h2>Tutorials</h2>
4749
The basic <a href=web/tutorial.html>Tutorials</a>
4850

4951
<h2>The Standard Library</h2>
50-
The <a href=packages/stdlib_toc>actual source code</a> of most
52+
The <a href=packages/stdlib_toc.html>actual source code</a> of most
5153
of the Felix standard library (Felix code) and the run time library (C++ code).
5254
There may be some bits missing from the index.
5355

5456
<h2>New Articles</h2>
5557
<ol>
5658
<li><a href=web/embedc.html>Embedding C/C++</a>
57-
<li><a href=webcorout.html>Coroutine Magic</a>
59+
<li><a href=web/corout.html>Coroutine Magic</a>
5860
</ol>
61+
jklhgsdjkhgjsdf
62+
jklhgsdjkhgjsdf
63+
jklhgsdjkhgjsdf
64+
jklhgsdjkhgjsdf
65+
jklhgsdjkhgjsdf
66+
jklhgsdjkhgjsdf
67+
jklhgsdjkhgjsdf
68+
jklhgsdjkhgjsdf
69+
jklhgsdjkhgjsdf
70+
jklhgsdjkhgjsdf
71+
jklhgsdjkhgjsdf
72+
jklhgsdjkhgjsdf
73+
jklhgsdjkhgjsdf
74+
jklhgsdjkhgjsdf
75+
jklhgsdjkhgjsdf
76+
jklhgsdjkhgjsdf
77+
jklhgsdjkhgjsdf
78+
jklhgsdjkhgjsdf
79+
jklhgsdjkhgjsdf
80+
jklhgsdjkhgjsdf
81+
jklhgsdjkhgjsdf
82+
jklhgsdjkhgjsdf
83+
jklhgsdjkhgjsdf
84+
jklhgsdjkhgjsdf
85+
jklhgsdjkhgjsdf
86+
jklhgsdjkhgjsdf
87+
jklhgsdjkhgjsdf
88+
jklhgsdjkhgjsdf
89+
jklhgsdjkhgjsdf
90+
jklhgsdjkhgjsdf
91+
jklhgsdjkhgjsdf
92+
jklhgsdjkhgjsdf
93+
jklhgsdjkhgjsdf
94+
jklhgsdjkhgjsdf
95+
jklhgsdjkhgjsdf
96+
</div>
5997
</body>
6098
</html>
6199

0 commit comments

Comments
 (0)