I’m totally stuck on a compile error, for some code that in other
contexts/functions works just fine.
It is reasonable that incrementing by 1 when less than 123 satisfies the
constraint. But it is not clear why in other contexts incrementing works,
but in this one it does not.
If I change to s.holdcnt := 0, it works fine. So it is trouble with the + 1.
Perhaps the constraint solver gets confused by multiple uses of a reference
in the same statement and does not know which is the “before” value vs. the
"after" value.
But it seems to be context sensitive. I have cases where it figures it out,
and can’t see any real difference in the code structure. I also noticed
that when I do it in a let clause, and then have a in clause, putting “"
vs “()” makes a difference. Sometimes with an "” the compiler is happy.
The type system does not track the types of the fields of a record.
You need to do the tracking explicitly:
implement
{}
next (s) =
let val n = s.holdcnt in if n < 123 then s.holdcnt := n+1 else s.err :=
s.err + ONEOn Sat, Jan 16, 2016 at 1:36 PM, Mike Jones proc...@gmail.com wrote:
I’m totally stuck on a compile error, for some code that in other
contexts/functions works just fine.
It is reasonable that incrementing by 1 when less than 123 satisfies the
constraint. But it is not clear why in other contexts incrementing works,
but in this one it does not.
If I change to s.holdcnt := 0, it works fine. So it is trouble with the +
1.
I too run into this problem often. I don’t know why the following (reduced
example) illustrates a work around. Assigning the value to a new var seems
to give ATS enough of a hint. I’m interested in the reason behind this as
much as you are sir.
typedef state = @{ holdcnt = natLte(123) … }
extern fun{} next (s: &state): void
implement{} next (s) = let
val holdcnt = s.holdcnt
…
in
if holdcnt < 123
then s.holdcnt := holdcnt + 1
else …
end
Best,
EricOn Saturday, January 16, 2016 at 1:36:15 PM UTC-5, Mike Jones wrote:
I’m totally stuck on a compile error, for some code that in other
contexts/functions works just fine.
It is reasonable that incrementing by 1 when less than 123 satisfies the
constraint. But it is not clear why in other contexts incrementing works,
but in this one it does not.
If I change to s.holdcnt := 0, it works fine. So it is trouble with the +
1.