Issue with call-by-reference and template dispatch

62 views
Skip to first unread message

M88

unread,
Jun 25, 2019, 9:47:50 AM6/25/19
to ats-lang-users
I noticed this a while ago in ATS2 (just verified in Temptory).

It seems that call-by-reference functions in record definitions cause issues with template dispatch.

The following will fail to compile ( no match for `do_something` ) -- changing  the signature of `foo.f` to `(int) -> void` will compile successfully.


#include "share/HATS/temptory_staload_bucs320.hats"

typedef foo = @{
  f
= (&int) -> void
}

extern
fun
{a:vtflt} do_something( a ) : void

impltmp
do_something
<foo>( x ) =
  let
     
var z : int = 0
   
in x.f(z)
   
end

implfun main0
()
   
= println!("Hello [test0]")
   
where {
     
var ff : foo = (@{
          f
= lam(x) => println!(x)
       
}): foo

     val
() = do_something<foo>(ff)
   
}




I've been using abstract types / casting as a work-around.
Message has been deleted
Message has been deleted

Richard

unread,
Jun 26, 2019, 8:13:41 AM6/26/19
to ats-lang-users
On Tuesday, June 25, 2019 at 9:47:50 AM UTC-4, M88 wrote:
> I noticed this a while ago in ATS2 (just verified in Temptory).
>
>
>
> It seems that call-by-reference functions in record definitions cause issues with template dispatch.
>

From what I can tell after some testing, a type defined as a function with call-by-reference seems to cause the same issue (even outside records).

>
> The following will fail to compile ( no match for `do_something` ) -- changing  the signature of `foo.f` to `(int) -> void` will compile successfully.
>
>
>
>
>
>
> #include "share/HATS/temptory_staload_bucs320.hats"
>
> typedef foo = @{
>   f = (&int) -> void
> }
>
> extern
> fun {a:vtflt} do_something( a ) : void
>
> impltmp
> do_something<foo>( x ) =
>   let
>      var z : int = 0
>    in x.f(z)
>    end
>
> implfun main0()
>    = println!("Hello [test0]")
>    where {
>      var ff : foo = (@{
>           f = lam(x) => println!(x)
>         }): foo
>
>      val () = do_something<foo>(ff)
>    }
>
>
>
>
> I've been using abstract types / casting as a work-around.

Could you share how you use abstract type / casting in this example to get it to work?

M88

unread,
Jun 26, 2019, 12:16:18 PM6/26/19
to ats-lang-users

This is how I get around the issue:


typedef Foo = @{

   f
= (&int) -> void
}


abstflt foo
= Foo
extern castfn reveal ( foo ) : Foo
extern castfn conceal ( Foo ) : foo

impltmp
do_something
<foo>( x ) =
   let
      val xx
= reveal ( x )

     
var z : int = 0

   
in xx.f( z )
   
end

implfun main0
()
 
= println!("Hello world")
 
where {
     
var ff : Foo = (@{

         f
= lam(x) => println!(x)

     
}) : Foo

      val _
= do_something<foo>( conceal( ff ) )


 
}



I did a little bit more testing, using the following definitions for "foo".


// Case 1
absprop FOO
typedef foo = @{
    f
= (FOO | int) -> void
}
// Case 2
absview FOO
typedef foo = @{
   f
= ( FOO | int ) -> void
}
// Case 3
typedef foo = @{
   f
= {l:addr}( !(int @ l) | ptr l ) -> void
}




The first two cases worked as expected, but the last one failed in the same way.  Maybe the issue is with at-views and template dispatch, specifically.

Hongwei Xi

unread,
Jun 26, 2019, 1:34:48 PM6/26/19
to ats-lan...@googlegroups.com
Right now, ATS2 cannot properly support the use of function types as template
parameters. I have no plan to fix it. Though, I expect that ATS3 be implemented to
properly handle function types as template parameters.

--
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 https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/8d5f8598-9955-43d8-9249-a7a5b222676d%40googlegroups.com.

M88

unread,
Jun 27, 2019, 8:45:41 PM6/27/19
to ats-lang-users
I see -- thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lan...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages