Effects detected in a seemingly pure function

I have implemented a comparison function to be used in the merge sort on
lists as below

implement list_mergesort$cmp<Tuple0(arity)> (x1, x2) =
let
fun loop {n:nat} .. (cols:list(@(Nat, List1(NatLt(arity))), n)) : int
case+ cols of
| list_nil() => 0
| list_cons( (_, indices), rest) =>
case+ indices of
| list_cons(index, _) =>
if (x1[index] > x2[index]) then 1
else if (x1[index] < x2[index]) then ~1
else loop(rest)
| _ =/=> loop(rest)
in
loop(extracted_cols)
end

The ATS compiler reports that, in the first call to loop (i.e., the line
before end), some
disallowed effects may be incurred. By searching in the mailing list, I
found that
$effmask_all(…) can be used to mask all the effects but I could not find
how it is
used. So, my first question is how $effmask_all is used.

My second question is what effect is the ATS compiler detecting? The exact
error
message I am getting is:
the_effenv_check_set: some disallowed effects may be incurred: 1
which does not seem to contain any information about the kind of effect I
should be
looking for.

Thanks,
Shahab

| _ =/=> loop(rest)

should probably be changed to

| _ =/=> ()

Actually, it can be eliminated as the compiler knows
this is an unreachable case.On Saturday, March 29, 2014 9:35:08 AM UTC-4, gmhwxi wrote:

The following declaration essentially indicates to the compiler that no
effect-tracking
is needed for ‘loop’:

loop {n:nat} .. (cols:list(@(Nat, List1(NatLt(arity))), n)) : int

If you change it to

loop {n:nat} .. (cols:list(@(Nat, List1(NatLt(arity))), n)) :<> int

then the code should type-check.

On Friday, March 28, 2014 11:52:29 PM UTC-4, Shahab Tasharrofi wrote:

I have implemented a comparison function to be used in the merge sort on
lists as below

implement list_mergesort$cmp<Tuple0(arity)> (x1, x2) =
let
fun loop {n:nat} .. (cols:list(@(Nat, List1(NatLt(arity))), n)) :
int =
case+ cols of
| list_nil() => 0
| list_cons( (_, indices), rest) =>
case+ indices of
| list_cons(index, _) =>
if (x1[index] > x2[index]) then 1
else if (x1[index] < x2[index]) then ~1
else loop(rest)
| _ =/=> loop(rest)
in
loop(extracted_cols)
end

The ATS compiler reports that, in the first call to loop (i.e., the line
before end), some
disallowed effects may be incurred. By searching in the mailing list, I
found that
$effmask_all(…) can be used to mask all the effects but I could not
find how it is
used. So, my first question is how $effmask_all is used.

My second question is what effect is the ATS compiler detecting? The
exact error
message I am getting is:
the_effenv_check_set: some disallowed effects may be incurred: 1
which does not seem to contain any information about the kind of effect I
should be
looking for.

Thanks,
Shahab

The following declaration essentially indicates to the compiler that no
effect-tracking
is needed for ‘loop’:

loop {n:nat} .. (cols:list(@(Nat, List1(NatLt(arity))), n)) : int

If you change it to

loop {n:nat} .. (cols:list(@(Nat, List1(NatLt(arity))), n)) :<> int

then the code should type-check.On Friday, March 28, 2014 11:52:29 PM UTC-4, Shahab Tasharrofi wrote:

I have implemented a comparison function to be used in the merge sort on
lists as below

implement list_mergesort$cmp<Tuple0(arity)> (x1, x2) =
let
fun loop {n:nat} .. (cols:list(@(Nat, List1(NatLt(arity))), n)) :
int =
case+ cols of
| list_nil() => 0
| list_cons( (_, indices), rest) =>
case+ indices of
| list_cons(index, _) =>
if (x1[index] > x2[index]) then 1
else if (x1[index] < x2[index]) then ~1
else loop(rest)
| _ =/=> loop(rest)
in
loop(extracted_cols)
end

The ATS compiler reports that, in the first call to loop (i.e., the line
before end), some
disallowed effects may be incurred. By searching in the mailing list, I
found that
$effmask_all(…) can be used to mask all the effects but I could not
find how it is
used. So, my first question is how $effmask_all is used.

My second question is what effect is the ATS compiler detecting? The exact
error
message I am getting is:
the_effenv_check_set: some disallowed effects may be incurred: 1
which does not seem to contain any information about the kind of effect I
should be
looking for.

Thanks,
Shahab

Effect-tracking is designed for something else. For your code, I would
suggest:

implement list_mergesort$cmp<Tuple0(arity)> (x1, x2) =
let
fun loop {n:nat} .. (cols:list(@(Nat, List1(NatLt(arity))), n)) : int
case+ cols of
| list_nil() => 0
| list_cons( (_, indices), rest) =>
case+ indices of
| list_cons(index, _) =>
if (x1[index] > x2[index]) then 1
else if (x1[index] < x2[index]) then ~1
else loop(rest)
| _ =/=> loop(rest)
in
$effmask_all(loop(extracted_cols))
endOn Saturday, March 29, 2014 3:15:28 PM UTC-4, Shahab Tasharrofi wrote:

Changing the code “:<> int” as you pointed out, moved the type-checking
error
to comparisons (i.e., x1[index] and x2[index]) which makes sense since they
are overloaded with method arrayref_get_at_gint which has a reference
effect in
its output.

Now, my question is that, since I am using x1[index] and x2[index] as right
values, how can I make sure that the reference effects are not passed
along to
the loop function?

Changing the code “:<> int” as you pointed out, moved the type-checking
error
to comparisons (i.e., x1[index] and x2[index]) which makes sense since they
are overloaded with method arrayref_get_at_gint which has a reference
effect in
its output.

Now, my question is that, since I am using x1[index] and x2[index] as right
values, how can I make sure that the reference effects are not passed along
to
the loop function?