forked from githwxi/ATS-Postiats
-
Notifications
You must be signed in to change notification settings - Fork 3
/
NOTES
424 lines (353 loc) · 7.59 KB
/
NOTES
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#
# HX:
#
# for myself to remember some significant features
# added into ATS2:
#
######
(*
** HX-2011-summer:
**
** Say that we have the following declared templates:
**
extern
fun
{a:t@ype}
{b,c:t@ype}
foo (x: a, y: b, z: c): void
**
** This is a style that is already supported in ATS:
**
implement{a}{b,c} foo (x, y, z) = ()
**
** This is a new style that is not available in ATS:
**
implement(b,c) foo<int><b,c> (x, y, z) = ()
**
** This style is added into ATS2 to support partial
** template instantiation.
**
*)
######
(*
** HX-2012-05:
**
** In ATS2, pattern matching involving linear types is
** re-designed. For instance, computing the length of a
** linear list can now be implemented as follows:
**
fun{a:viewt@ype}
length {n:int}
(xs: !list_vt (a, n)): int (n) =
case+ xs of
| list_vt_cons (x, xs) => 1 + length (xs)
| list_vt_nil () => 0
// end of [length]
**
** As another example, reverse-append on linear lists
** can now be implemented as follows:
//
fun{a:viewt@ype}
revapp {m,n:nat} .<m>. (
xs: list_vt (a, m), ys: list_vt (a, n)
) :<> list_vt (a, m+n) =
case xs of
| @list_vt_cons
(_, xs1) => let
val xs1_ = xs1
val () = xs1 := ys; prval () = fold@ (xs)
in
revapp (xs1_, xs)
end
| ~list_vt_nil () => ys
(* end of [revapp] *)
//
**
*)
######
(*
**
** HX-2012-05:
**
** Say we have a type
**
** absviewt@ype T (l:addr)
**
** Let T0 be defined as follows:
**
** typedef T0 = [l:addr] T(l)
**
** The difference between the following two function decs
** is somewhat subtle:
**
** fun f1 (x: &T0): void
** fun f2 (x: &T0 >> T0): void
**
** The dec for function [f1] is essentially equivalent to
** the following one:
**
** fun f1 {l:addr} (x: &T(l) >> T(l)): void
**
** So if [f1] is called on a left-value of the type T(L)
** for some L, then the type of the left-value is still T(L)
** after the call. On the other hand, if [f2] is called,
** the type of the left-value may be T(L') for some L' != L.
**
*)
######
(*
**
** HX-2012-05-24:
**
** for synthesizing the second arg of S1Etrans:
** T >> _ stands for T >> T
** T >> _? stands for T >> T?
** T >> _?! stands for T >> T?!
** T? >> _ stands for T? >> T
**
*)
######
(*
**
** HX-2012:
**
** The skeleton of a type is computed by erasing all
** quatifiers and predicative indexes; type skeletons
** are primarily employed to support overloading.
**
** The size of each boxed type equals that of a pointer.
** The size of each unboxed type is only determined by
** its skeleton. In other words, predicative indexes are
** ignored for the purpose of comparing type sizes.
**
*)
######
(*
**
** HX-2012-05:
**
** Dynamic expressions like A[i,j][k] are referred to as
** arrsub-expressions in ATS; for such expressions, grouping
** is entirely cosmetic; for example, both A[i,j][k] and
** A[i][j,k] are the same, and they are the same as A[i,j,k].
**
*)
######
(*
**
** HX-2012-06-01:
**
** Introducing the following syntax to support typechecking:
**
** lam {} => ...
**
** 'lam {}' means an indefinite number of static lam-abstractions.
**
** Actually, the first of the following two lines is the same as
** the second of them:
**
** lam (...) => ...
** lam {} => lam (...) => ...
**
** Hence, 'lam {}' is only needed in a case where its body is not
** a dynamic lambda-abstraction. A good example involving 'lam {}'
** can be found in doc/EXAMPLE/ATSLF/SMI.dats.
**
*)
######
#
# The following was in the old README
#
######
Project Title: ATS/Postiats
Project Description:
Another Implementation of ATS!
######
//
// HX-2011-03-07: syntax design:
//
&? >> T for &T? >> T
This can be &set(T)
&T >> ?! for &T >> T?!
This can be &get(T)
&T >> ? for &T >> T?
This can be &clr(T)
######
//
// HX-2011-03-13
//
Optmizing pattern matching compilation
######
//
// HX-2011-03-14
//
Each type should be given a generic name as well as a specific name;
the former for generic template instantiation and the latter for specific
template implementation.
######
//
// HX-2011-03-16
//
Handling read-only access.
fun f (x: &READ(Int)): bool
######
//
// HX-2011-03-20
//
Some kind of sort inferencing (for impredicative sorts).
######
//
// HX-2011-03-21
//
Supporting user-defined effects
######
//
// HX-2011-03-30
//
Supporting invariant types:
fun{a1,a2:t@ype} f (x: INV(a1), y: INV(a2)): (a1, a2)
######
//
// HX-2011-04-15
//
Macro support for patterns.
(*
HX-2011-04-27:
there is now support for functional C-like macros. For instance,
the following declaration is now available, which I plan to turn
into limited macro support for patterns:
//
#define list_sing (x) list_cons (x, list_nil ())
//
*)
######
//
// HX-2011-08
//
fold/unfold are proof functions
encode/decode are casting functions (castfn)
ifbrk $test then $exp
for
if $test then ($exp; break)
ifcnt $test then $exp
for
if $test then ($exp; continue)
######
//
// HX-2011-08
//
logging errors of lib functions of the names *_exn?
######
//
// HX-2011-08
//
mutability:
structbox = '{
name= string, width= !int, height= !int
} // it is just like a ref!
######
//
// HX-2011-09
//
A flag for allocation-only GCATS.
######
From [email protected] Sun Sep 4 16:50:34 2011
Date: Sun, 4 Sep 2011 22:50:19 +0200
From: Matthias Berndt <[email protected]>
To: <[email protected]>
Subject: Re: [ats-lang-users] Error code checking with linear types
Hi Hongwei,
> >>Wouldn't it be possible to just DWIM in that case? For example, an
> >>expression like
> >>case x of
> >>
> >> | (a | b) => ...
> >> | (c | d) => ...
> >>
> >>could automatically be transformed into something like
> >>let val+ (x1 | x2) = x in
> >>
> >> case x2 of
> >>
> >> | b => let prval a = x1 in ... end
> >> | d => let prval c = x1 in ... end
>
> When [b] matches [x2], [a] may not be the only pattern that matches x1;
> if it is the only one, then yes.
Yes, this would be a shorthand for the (common?) case where the fact that
x2 matches b also implies that x1 matches a. For all other cases, one needs
to resort to the solution we have now.
> By the way, what does 'DWIM' stand for?
"Do What I Mean".
######
//
// HX: this form of pseudo abstract type can also be useful
//
abst@ype
E (a:t@ype, x:elt) = !a
assume E (a:t@ype, x:elt) = top // ignored
######
//
// HX-2011-10-01: supporting offsetof?
//
######
######
//
// HX-2011-10-18: proof management?
//
#proof (?@l)
#proof (array_v(?, ?, l))
#typeof (exp)
let
prfun tyeq {a:t@ype} (x: INV(a)): void
prfun tyeq_vt {a:t@ype} (x: !INV(a)): void
prval pf = #proof(?@l)
prval pf = #proof(free_v_gc(?, l))
stavar i: int and j: int
prval () = tyeq {int(i)} (x+y)
val x = ptrget (pf | p)
in
end // end of [
######
//
// HX-2012-02-08: caseof-expressions
//
fun fact
(x: int): int =
caseof x > 0 => x * f (x-1) | (*else*) => 1
// end of [fact]
######
explicit wthtype syntax:
(int? >> opt (int i, b)) -> #[i:nat;b:bool] bool (b)
######
A convenient syntax for handling folding/unfolding:
fun{
a:viewt@ype
} list_vt_length
(xs: !list_vt (a, n)): int n =
case+ xs of
| list_vt_cons (x, xs) => 1 + list_vt_length (xs)
| list_vt_nil () => 0
// end of [list_vt_length]
fun{
a:viewt@ype
} list_vt_append
{m,n:int | m > 0} (
xs: !list_vt (a, m) >> list_vt (a, m+n)
, ys: list_vt (a, n)
) : void = let
val @list_vt_cons (_, xs1) = xs
in
case+ xs1 of
| list_cons _ => let
val () = list_vt_append (xs1, ys) in fold@ (xs)
end // end of [list_cons]
| ~list_vt_nil () => xs1 := ys
end // end of [list_vt_append]
######
HX-2013-06-20:
Is it a good practice to allow the use of wildcards (_ or ...)
for discarding resources:
Pro: Very easy to use
Con: Maybe it is too easy to allow unintentional leak of resources
###### end of [NOTES] ######