Match failure: scalar * matrix

fun{

a:t0p

} mul_scalar_matrix
{m,n:int}
(
c: a
, A: &matrix (a, m, n)
, m: size_t m, n: size_t n
) : void // end of [mul_scalar_matrix]

(* ****** ****** *)

implement{a}
mul_scalar_matrix
{m,n} (c, A, m, n) = let
//

val pA = addr@(A)
//

prval pfA = matrix2array_v (view@(A))
macdef * = gmul_val
//

//var !mul_c = @lam(x: &a):a => let val () = x := cx in ( *) end //Tried following Chris’s stack-allocated ATS(1) example

val mul_c = lam(pfmcl | x: &a): a =<cloptr,!wrt> let val () = x := cx in
(
*) end
//

val () = array_foreach_cloptr (A, m*n, mul_c)
//

prval () = view@(A) := array2matrix_v {a}{…}{m,n} (pfA)
in // in of [mul_scalar_matrix]

//nothing

end (* end of [mul_scalar_matrix] )
(
end of [matrix.dats] *)

When I try to add these to matrix.sats and matrix.dats, I get the following:

the_effenv_check_sexp: s2e0 = S2Evar(fe(5045))
the_effenv_check_sexp: s2e0 = S2Evar(fe(5045))
the_effenv_check_sexp: s2e0 = S2Evar(fe$1356(5216))
the_effenv_check_sexp: s2e0 = S2Evar(fe$1361(5222))
exit(ATS):
/media/RAID5/share/ATS_learning/ATS-Postiats/src/pats_trans3_env_dvar.dats:
22054(line=928, offs=9) – 22092(line=928, offs=47): match failure.
make: *** [matrix_test_dats.c] Error 1

I believe I need to somehow specify to array_foreach_cloptr the function
effect wrt.

The function can now be written as follows:

extern
fun{a:t0p}
mul_scalar_matrix
{m,n:int}
(
c: a
, A: &matrix (INV(a), m, n) >> _
, m: size_t m, n: size_t n
) : void // end of [mul_scalar_matrix]

implement{a}
mul_scalar_matrix
(c, A, m, n) = let
//
implement(env)
matrix_foreach$fwork (x, env) = x := gmul_val (c, x)
//
in
matrix_foreach
(A, m, n)
end // end of [mul_scalar_matrix]

PS: I just added matrix_foreach.

In the following code, ‘pfmcl’ is not assigned a type.

val mul_c = lam(pfmcl | x: &a): a =<cloptr,!wrt> let val () = x := cx in
(
*) end

That ‘pfmcl’ is not assigned a type triggered a bug in the ATS2 compiler. I
think I have now fixed the problem.

Cheers!