-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathl.htm
245 lines (205 loc) · 8.38 KB
/
l.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="Maxim Sokhatsky" />
<title>EXE</title>
<link rel="stylesheet" href="5HT.css" />
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</head>
<body>
<div class=menu>
<a href="index.html">articles</a>
</div>
<hr>
<div class=app>
<div align=right>FROM: 5HT<br>
TO: MAXIM KHARCHENKO<br>
DATE: 5 MAR 2015</div>
<h2>Language L: Type Inspector</h2>
<div class=message>
<p>The L is an emerging modern functional language
LLVM compiler for Xen applications by <b>cloudozer</b>.
This document is dedicated to a proposition of a concise and
holistic syntax for type inspector, the front end of
type inferrer, visible to user in future L repl.</p>
<h3>Overview</h3>
<p>The basic feature of L and its type system is that it is able
to infer the infinite non-terminated structures from codata as it
could be found in <b>F<sub><:</sub></b> type system.</p>
<h4>Recursive Types</h4>
<div class=note style="background-color:#FAFAFA;"><p>Code Sample:<br>
<code>
rev [] xs -> xs;
rev [x|xs] ys -> rev xs [x|ys].
</code><p></div>
<div class=note><p>Infered recursive infinite
list as the second argument in rev/2 codata:</b>
<pre>
:: rev = fun: x y -> y
y: z -> {z,y•z}
x: z -> (nil | {z,x•z})
</pre>
</p></div>
<h4>Subtypes</h4>
<h4>Intersection Types</h4>
<!--p><font color=#D0021B>
Попытаемся универсализировать синтаксис отладчика типов.
Пускай отладчик на каждое имя: Функции, Типа данных или
Модуля выводит сразу имя головного уравнения, и уравнения
типовых переменных которые упоминаются в сигнатуре
(главном входящем уравнении). Так например для любой
переменной мы сможем автоматически назвать головоное
уравнение именем типа: fun (уравнения функций, <b>codata</b>),
type (уравнения типов данных, <b>data</b>), module (уравнения модулей,
как список любых типов, функций, данных, <b>cat</b>).
Я заметил что сейчас lc -t не детализируют перменную z,
поэтому я ее тут привел явно, чтобы все соотвествовало
формулам в статье newer_types.</font>
</p-->
<!--div class=note><p>NOTE: As you may see L is pretty good in infering infinite lists.</p></div-->
<h3>Type Inspector Syntax</h3>
<p>The syntax of the type solver is the part of L that is able to solve a given
equations with respect to order of subtyping (marked by <b>"<"</b> symbol) and
named recursive types (marked as <b>":"</b> symbol).</p>
<div class=note><p> <pre>
Equation = :: Term = [ Form ]
Form = Nomen | Subtype
Subtype = Type < Type .
Nomen = Atom : Type .
Type = App -> Arrow
App = App * Data
App = Data
Data = Const | Var | Cell
| Product
| Sum
| Nomen
| ( Type )
</pre></p></div>
<br>
<div class=note><p>Sample Equation<pre>
:: r02.t = F: x1 -> G * x1 * int.
G: int -> int -> int.
H: ( nil -> x2 -> x2 | [x3|y3] ->
z3 -> H * y3 * z3 ).
I: ( nil -> x4 -> x4 | [x5|y5] ->
z5 -> G * y5 * (I * x5 * z5) ).
G < H.
I < F.
F < (nil | G).
</pre> You may solve it with
<pre>
ti -s r02.t
</pre></p></div>
<h4>Constructors</h4>
<p>Type inspector syntax opens a clean view on
type declarations as a form of equations bounded in a naming context.
The output of Type Inferer is exatcly match the types declaration
syntax and the syntax of Type Inspector. The type infere detects
cycles in polymorphic parameters and split inerred type
on recursive nomens.
.</p>
<div class=note>
<pre>
:: intList = type: (nil | {int,type})
:: list = type: x -> (nil | {x,type•x})
:: pairsList = type: x y -> (nil | {{x,y},type • x y})
:: binTree = type: x -> (nil | {type•x,x,type•x})
:: listsList = type: f
f: x -> (nil | {g•x,f•x})
g: x -> (nil | {x,g•x})
:: variadicTree = type: f
f: x -> (nil | {x,g•x})
g: x -> (nil | {f•x,g•x})
:: lists = module: rev
rev: l y -> y
l: x -> (nil | {x,l•x})
y: z -> {z,y•z}
</pre>
</p></div>
<h3>Type System</h3>
<p>Some types are embedded in L core to resolve main tasks during
type inference, type unification and patterm maching compilation.
L has following basic types which are used by infer/unify/match core.
These types are also shared with Type Inspector.</p>
<div class=note style="background-color:#fafafa;"><p>Types of programs<ul>
<li>Product <code>{,}</code></li>
<li>Sum <code>(|)</code></li>
<li>Fun <code>-></code> codata</li>
<li>Type <code></code> data</li>
<li>Module <code></code> cat</li>
</ul></p></div>
<div class=note><p>Types in equations<ul><li>Arrow <code>-></code> </li>
<li>Application <code>•</code> </li>
<li>Subtyping <code><</code></li>
<li>Nomen <code>:</code></li>
<li>Equation<code>=</code></li>
</ul></p></div>
<p>During type inference we also operate such type instances as
Constants, Variables, Constructors and Wildcards.</p>
<h4>Binary Tree</h4>
<div class=note style="background-color:#FAFAFA;"><p>
<code>cons t -> cons t [].
cons [] acc -> acc;
cons {l,x,r} acc -> cons r (cons l [x|acc]).
</code><p></div>
<div class=note><p>Infered recursive infinite
list as the second argument in rev/2 codata:</b>
<pre>
:: cons = G: ( nil -> x -> x
| {x,y,z} -> u -> G * z * (G * x * [y|u]) ).
</pre>
</p></div>
<h4>User Manual</h4>
<div class=note><p>Working with Type Inspector</p>
<pre>
./typer
> l z5.t
> p
F: x -> G * x * nil
G: ( nil -> x -> x
| {x,y,z} -> u -> G * z * (G * x * [y|u]) )
> h
all = dawn sweep ncy
dawn = nv de
sweep = cn1 eq1 cd
ncy: check the definitions does not contain cycles
nv: replace all variables with nomens
de: derive subtyping equations
cn1: [heuristic] (X | Y | Z ...) => X = Y = Z
eq1: X: Y => X = Y
eq2: X: t, Y: t => X = Y
cd: X: C => X = C
mc: match constructors
cn2: [heuristic] X < Y => X = Y
re1: t1 < X, t2 < X => (t1 | t2) < X
re2: [heuristic] X < t1, X < t2 => X < t1, t1 < t2
re3: [heuristic] t1 < X, X < t2 => X: t1, t1 < t2
tc: t1 < X, X < t2 add t1 < t2
xn: expand all non-cyclic nomens in equations
fe: [heuristic] X < t => X: t
du: remove unused non-root nomens
dr: remove repetitions
</pre>
</p></div>
<!--font color=#D0021B>
<p>
Так например здесь приведены уравнения для простых типов
данных и слишком рекурсивных которые в одно уравнение не
помещаются. Приведен пример синтаксиса для гипотетического
модуля, просто как контейнера для других типов, но который
по сути просто набор уравнений.</p>
<p>В уравнениях я так понимаю, что
типы данных отличаются от типов функций тем, что Application
не встречается в уравнениях функций, а только в уравнения типов.
Но если Application нет в типе данных, то такая сигнатура
может быть неотличимы от сигнатуры функции. Только если
отдельно спросить у отладчика типов тип этой переменной, то
можно будет по имени корневого уравнения узнать тип этой
типовой переменной.</p></font-->
</div>
</div>
</body>
</html>