Templates and closures

28 views
Skip to first unread message

chotu s

unread,
Mar 11, 2014, 12:10:17 PM3/11/14
to ats-lan...@googlegroups.com
Hello ,

Any idea why test2 function does not work in this code :

#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
staload UN = "prelude/SATS/unsafe.sats"


extern
fun{a:t@ype}
test (f : &(&int) -<clo1> void ) : void

implement{a}
test (f) = {}

extern
fun{a:t@ype}
test2(f : &(&a) -<clo1> void ) : void

implement{a}
test2 (f) = {}

implement main0 () = {
  var f = lam@ (x : &int) : void => {} 
  val () = test<int> (f)
  val () = test2<int> (f)
}


gmhwxi

unread,
Mar 11, 2014, 1:28:33 PM3/11/14
to ats-lan...@googlegroups.com
This involves a very subtle point in typechecking.

The code should work if you make the following change:

extern
fun
{a:t@ype}
test2
(f : &(&(INV(a)) -<clo1> void ) : void

chotu s

unread,
Mar 12, 2014, 1:01:41 AM3/12/14
to gmhwxi, ats-lan...@googlegroups.com
Thanks , it now works properly. I'll look at INV later.

In array.sats (development version , 0,0,07) , the array_foreach_clo is define like this :

fun{a:vt0p}
array_foreach_clo
  {n:int}{fe:eff}
(
  A: &(@[INV(a)][n])
, asz: size_t n
, f: &(&a) -<clo,fe> void
) :<fe> void // end of [array_foreach_clo]


Should it not be defined like this :

extern
fun{a:vt0p}
array_foreach_clo
  {n:int}{fe:eff}
(
  A: &(@[INV(a)][n])
, asz: size_t n
, f: &(&(INV(a))) -<clo,fe> void
) :<fe> void // end of [array_foreach_clo]


only difference is in type of f .




--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/2c45b72d-c72c-44ac-8935-741850ae00b3%40googlegroups.com.

chotu s

unread,
Mar 12, 2014, 1:09:43 AM3/12/14
to gmhwxi, ats-lan...@googlegroups.com
Can I also make closure function name visible inside a nested function i.e

implement{a}
fun (A,B,f) = {
 implement somefun<a> () = //make f visible here
 .....
}

 

gmhwxi

unread,
Mar 12, 2014, 1:20:45 AM3/12/14
to ats-lan...@googlegroups.com, gmhwxi
I took a look. It should be:

fun{a:vt0p}
array_foreach_clo
 
{n:int}{fe:eff}
(

  A
: &(@[INV(a)][n]) >> @[a][n]
, asz: size_t (n), f: &(&a >> _) -<clo,fe> void

) :<fe> void // end of [array_foreach_clo]

I have to say that this function and similar ones are kept mainly for the purpose of
indicating how awkward the situation was in ATS1.

I suggest that you use array_foreach and array_foreach_env.

gmhwxi

unread,
Mar 12, 2014, 1:23:22 AM3/12/14
to ats-lan...@googlegroups.com, gmhwxi
Yes, you can.
Reply all
Reply to author
Forward
0 new messages