INV in ATS2

191 lượt xem
Chuyển tới thư đầu tiên chưa đọc

Brandon Barker

chưa đọc,
12:48:27 9 thg 7, 20139/7/13
đến ats-lan...@googlegroups.com
Just curious what INV means.

Thanks,
Brandon

gmhwxi

chưa đọc,
13:35:33 9 thg 7, 20139/7/13
đến ats-lan...@googlegroups.com
INV is for invariant.

It is essentially marker for typechecking.

For instance, say you have a funtion foo
declared as follows:

fun{a:t@ype} foo (xs: list0 (INV(a))): void

Assume that mylst is of the type list0 (T) for some T.
When typechecking foo(mylst), the typechecker will expand
the expression as follows by picking a placeholder T1:

foo<T1>(mylst)

where T <= T1 is assumed.

Say that foo2 is declared as follows:

fun{a:t@ype} foo2 (xs: list0 (INV(a))): void

When foo2(mylst) is typechecked, the typechecker simply
expands the expression to foo2<T>(mylst).

Brandon Barker

chưa đọc,
17:59:31 9 thg 7, 20139/7/13
đến ats-lan...@googlegroups.com
So I think this comes full circle to my very first question about ATS:

If this is the case, I believe there is just a minor typo in your example above, where foo should not use INV:

fun{a:t@ype} foo (xs: list0 (a)): void

This seems like a good feature to know about! Perhaps even more interesting is thinking of ways to use the absence of INV, by learning uses of covariant types.

gmhwxi

chưa đọc,
19:07:03 9 thg 7, 20139/7/13
đến ats-lan...@googlegroups.com
Right. It is typo as you pointed out.

Kiwamu Okabe

chưa đọc,
23:37:47 18 thg 6, 201518/6/15
đến ats-lan...@googlegroups.com
On Wednesday, July 10, 2013 at 2:35:33 AM UTC+9, gmhwxi wrote:
fun{a:t@ype} foo (xs: list0 (INV(a))): void

Assume that mylst is of the type list0 (T) for some T.
When typechecking foo(mylst), the typechecker will expand
the expression as follows by picking a placeholder T1:

foo<T1>(mylst)

where T <= T1 is assumed.

What is "T1"?
 

Hongwei Xi

chưa đọc,
23:40:18 18 thg 6, 201518/6/15
đến ats-lan...@googlegroups.com
A type.


--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/2acc15f3-ffba-40fd-b5c2-e99db819e94e%40googlegroups.com.

Kiwamu Okabe

chưa đọc,
23:44:45 18 thg 6, 201518/6/15
đến ats-lang-users
On Fri, Jun 19, 2015 at 12:40 PM, Hongwei Xi <gmh...@gmail.com> wrote:
> A type.

Umm...
In conclusion, ATS's template engine can't guess correct type variable
without INV?
--
Kiwamu Okabe at METASEPI DESIGN

Hongwei Xi

chưa đọc,
23:51:08 18 thg 6, 201518/6/15
đến ats-lan...@googlegroups.com


The reason is that there are many possibilities, all of which can be "correct".

For instance, cons(10, nil) can have infinitely many types:

list(int, 1)
list(int(10), 1)
list(intGte(10), 1)

Without INV, the programmer has to pass types explicitly.
....

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.

Kiwamu Okabe

chưa đọc,
23:52:13 18 thg 6, 201518/6/15
đến ats-lan...@googlegroups.com, kiw...@debian.or.jp
On Friday, June 19, 2015 at 12:44:45 PM UTC+9, Kiwamu Okabe wrote:
In conclusion, ATS's template engine can't guess correct type variable
without INV?

May I set INV into return value of function such like following?

fun{a:t@ype} pal_empty
  (): (PAL (ilist_nil) | gflist (INV(a), ilist_nil ()))

Hongwei Xi

chưa đọc,
23:56:41 18 thg 6, 201518/6/15
đến ats-lan...@googlegroups.com
You can but it does not work here.
The above example should be written as follows:

fun{} pal_empty{a:t@ype} ...

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.

Yannick Duchêne

chưa đọc,
17:41:40 23 thg 8, 201523/8/15
đến ats-lang-users


Le vendredi 19 juin 2015 05:51:08 UTC+2, gmhwxi a écrit :


The reason is that there are many possibilities, all of which can be "correct".

For instance, cons(10, nil) can have infinitely many types:

list(int, 1)
list(int(10), 1)
list(intGte(10), 1)

Without INV, the programmer has to pass types explicitly.
 
Is it correct to understand it as a bit similar to the “like” clause in Eiffel?

gmhwxi

chưa đọc,
23:08:48 23 thg 8, 201523/8/15
đến ats-lang-users
I just see it as some sort of syntactic annotation
for the purpose of simplifying contraint-solving:

If the following constraint is encountered:

INV(X) <= T (where X is a unification variable),

then it is automatically turned into (X = T).
Trả lời tất cả
Trả lời tác giả
Chuyển tiếp
0 tin nhắn mới