sortdef set = t@ype
abst@ype set(s: set)
typedef set = [s: set] set s
sortdef item = string
abstype item(i: item)
typedef item = [i: item] item i
extern fn item(): item
stacst has(s: set, i: item): bool
extern fn has{s: set; i: item}(s: set s, i: item i): bool(has(s, i))
extern fn empty(): [s: set] {i: item | ~has(s, i)} set s
val s = empty()
val i = item()
val b = has(s, i)
error(3): unsolved constraint: C3NSTRprop(main; S2Eapp(S2Ecst(~); S2Eapp(S2Ecst(has); S2Evar(s$1078$1080(4460)), S2EVar(140))))
Hi all,Until now, I though the predicate on a function result, was an assertion about the result, not more. I'm stuck since some hours trying to understand why it seems to become a constraint on another function parameter.The concrete sample will tell more (not too long, I hope):
sortdef set = t@ype
abst@ype set(s: set)
typedef set = [s: set] set s
sortdef item = string
abstype item(i: item)
typedef item = [i: item] item i
extern fn item(): item
stacst has(s: set, i: item): bool
extern fn has{s: set; i: item}(s: set s, i: item i): bool(has(s, i))
extern fn empty(): [s: set] {i: item | ~has(s, i)} set s
val s = empty()
val i = item()
val b = has(s, i)
[…]
Here how I understood the predicate when I wrote it: “there exist a set s, such that for any item i, has(s, i) does not hold, and this such a set s which this function returns”.
extern fn empty {i: item}(): [s: set | ~has(s, i)] set s
This one seems OK (unless I later discoverer it does not mean what I think):
extern fn empty {i: item}(): [s: set | ~has(s, i)] set s
Is that this one which means “there exist a set s, such that for any item i, has(s, i) does not hold, and this such a set s which this function returns”? If yes, what means the other?
extern fn empty (): [s: set] {i: item | ~has(s, i)} set s
extern fn empty (): [s: set] {i: item} {~has(s, i)} set s
extern fn empty(): [s: set | {i:item} has(s, i)] set(s)
extern fn empty(): [s: set] ({i:item} () -> [has(s, i)] void | set s)
The right way is this:
extern fn empty(): [s: set | {i:item} has(s, i)] set(s)
But it is not supported. The closest way I can think of is this:
extern fn empty(): [s: set] ({i:item} () -> [has(s, i)] void | set s)
On Saturday, May 16, 2015 at 7:50:42 AM UTC+6, gmhwxi wrote:
The right way is this:
extern fn empty(): [s: set | {i:item} has(s, i)] set(s)
But it is not supported. The closest way I can think of is this:
extern fn empty(): [s: set] ({i:item} () -> [has(s, i)] void | set s)
How about this one?
absprop EMPTYSET (set)
extern praxi emptyset_elim : {s:set} {i:item} EMPTYSET (s) -> [~has (s, i)] void
extern fn empty (): [s: set] (EMPTYSET (s) | set s)
Looks good.
Or
stacst emptyset: set
extern fun emptyset(): set(emptyset)
extern prfun lemma_emptyset{i:item}(): [~has(emptyset, i)] void.
Le samedi 16 mai 2015 06:12:39 UTC+2, Artyom Shalkhakov a écrit :
absprop EMPTYSET (set)
extern praxi emptyset_elim : {s:set} {i:item} EMPTYSET (s) -> [~has (s, i)] void
extern fn empty (): [s: set] (EMPTYSET (s) | set s)
Yes, I agree. I too though an inductive definition may be a good alternative […]
Hi all,Until now, I though the predicate on a function result, was an assertion about the result, not more. I'm stuck since some hours trying to understand why it seems to become a constraint on another function parameter.The concrete sample will tell more (not too long, I hope):
sortdef set = t@ype
abst@ype set(s: set)
typedef set = [s: set] set s
sortdef item = string
abstype item(i: item)
typedef item = [i: item] item i
extern fn item(): item
stacst has(s: set, i: item): bool
extern fn has{s: set; i: item}(s: set s, i: item i): bool(has(s, i))
extern fn empty(): [s: set] {i: item | ~has(s, i)} set s
val s = empty()
val i = item()
val b = has(s, i)
PATSOPT complains about a constraint error with the `s` parameter in `val b = has(s, i)`. It complains it can't verify `~has(x, y)` where `x` and `y` are variables […]
--
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/0e90398e-c7f7-4463-842b-34dce18deef0%40googlegroups.com.
Clearly, this is not something you want here.(statically) apply 'xyz' to 'i' to get something of the type set(s): 'xyz{i}'you need to find an 'i' such that 'has(s, i)' is false and then'xyz' has the type '{i: item | ~has(s, i)} set s' for some s;>>fn empty(): [s: set] {i: item | ~has(s, i)} set sval xyz = empty()
How to read these expressions precisely, is a must-know.
val v = f()
val _ = showtype(v)
val _ = showtype(f())
extern fn empty1(): set
extern fn empty2(): [s: set] set s
extern fn empty3(): {i: item} set
extern fn empty4(): {i: item} [s: set] set s
extern fn empty5(): [s: set] {i: item} set s
extern fn empty6(): [s: set] {i: item | ~has(s, i)} set s
val s = empty1()
val _ = showtype(empty1())
val _ = showtype(s)
val s = empty2()
val _ = showtype(empty2())
val _ = showtype(s)
val s = empty3()
val _ = showtype(empty3())
val _ = showtype(s)
val s = empty4()
val _ = showtype(empty4())
val _ = showtype(s)
val s = empty5()
val _ = showtype(empty5())
val _ = showtype(s)
val s = empty6()
val _ = showtype(empty6())
val _ = showtype(s)
S2Ecst(set)
S2Eapp(S2Ecst(set); S2Evar(s))
As an example, in the first group of test, `showtype(empty1())` says (dropping the sort to make it shorter):
S2Ecst(set)
while `showtype(s)` says:
S2Eapp(S2Ecst(set); S2Evar(s))
Why isn't it the same? As there is no type annotation on `s`, why does it change?I noticed `showtype(f())` always shows the exact same as in the signature of f, but not the same on a value which is bound to `f()`.
Say you have a value v of the type [s:set] set(s).
You can do:
val [s1:set] v1 = v // [s1:set] v1 is a pattern
The type for v1 is set(s1).
If you do:
val v1 = v
The type for v1 is set(s1) for some s1 chosen by the typechecker.
This is often referred to as automatic unpacking a value of existentially
quantified type.
The basic rule is that every value of an existentially quantified type is
always unpacked before it is passed to a function.
Details on typechecking in are here:
http://www.ats-lang.org/MYDATA/DML-jfp07.pdf
See the section on elaboration.
[…] and also one have to write ``
Clearly, this is not something you want here.(statically) apply 'xyz' to 'i' to get something of the type set(s): 'xyz{i}'you need to find an 'i' such that 'has(s, i)' is false and then'xyz' has the type '{i: item | ~has(s, i)} set s' for some s;>>fn empty(): [s: set] {i: item | ~has(s, i)} set sval xyz = empty()
Indeed, I could not be more wrong. That's part of the tips to always have in mind, like one must be aware of not mistakenly writing a template parameter instead of polymorphic parameter (`fn {…} f()` vs `fn f {…}()`), one must not loose track of the subject of a predicate. And in `{i: item | ~has(s, i)}`, the subject is `i`, not `s`. To remember it, one may think about the simple `sortdef pos = {n: nat | n >= 1}` (I should shout at myself for such a mistake). That's something easy to forgot about when on the run.
S2Eexi(
s;
(none);
S2Euni(
i;
S2Eapp(
S2Ecst(~);
S2Eapp(
S2Ecst(has);
S2Evar(s),
S2Evar(i)
)
);
S2Eapp(
S2Ecst(set);
S2Evar(s)
)
)
)
(statically) apply 'xyz' to 'i' to get something of the type set(s): 'xyz{i}'you need to find an 'i' such that 'has(s, i)' is false and then'xyz' has the type '{i: item | ~has(s, i)} set s' for some s;>>fn empty(): [s: set] {i: item | ~has(s, i)} set sval xyz = empty()
--
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/d25c12a9-b04f-4ba7-8cb6-fc92b5422d39%40googlegroups.com.
Looks good.
Or
stacst emptyset: set
extern fun emptyset(): set(emptyset)
extern prfun lemma_emptyset{i:item}(): [~has(emptyset, i)] void.
extern praxi lemma_empty{i:item}(): [~has(empty, i)] void
extern praxi lemma_empty(): {i:item}[~has(empty, i)] void
prval lemma_empty = lemma_empty()
val s = empty()
val [i: item] i = item()
prval () = lemma_empty{i} // <-- here
val b:bool(false) = has(s, i)
prval () = lemma_empty{i}()
The right way is this:
extern fn empty(): [s: set | {i:item} has(s, i)] set(s)
But it is not supported. The closest way I can think of is this:
extern fn empty(): [s: set] ({i:item} () -> [has(s, i)] void | set s)
extern fn empty(): [s: set] ({i:item} [~has(s, i)] void | set s)
extern fn empty(): [s: set] ({i:item} [~has(s, i)] void, set s)
extern fn empty(): [s: set] ({i:item} [~has(s, i)] void, set s)
--
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/9bfd0e7b-cae8-48ee-8180-4c59eabc458d%40googlegroups.com.
Note that a type is always a prop but a prop is not necessarily a type.If you write (T1 | T2), then T1 is definitely erased after typechecking.If you write (T1 , T2), then T1 is erased only if it is of the sort 'prop'.
val a:int:prop = 0
In the following case, a compilation error is expected because C does notallow void to be part of a struct.
extern fn empty(): [s: set] ({i:item} [~has(s, i)] void, set s)
How about this one?
absprop EMPTYSET (set)
extern praxi emptyset_elim : {s:set} {i:item} EMPTYSET (s) -> [~has (s, i)] void
extern fn empty (): [s: set] (EMPTYSET (s) | set s)
propdef EMPTYSET(s:set) = {i:item} [~has(s, i)] void
extern fn empty(): [s: set] (EMPTYSET(s) | set s)