Only for arrays of fixed size.
Here is a sketch for arrays of size 2:
(* ****** ****** *)
#include
"share/atspre_staload.hats"
(* ****** ****** *)
abst@ype
htuple2(a:t@ype) = @(a, a)
(* ****** ****** *)
//
extern
fun
{a:t@ype}
htuple2_make
(x: a, y: a): htuple2(a)
//
extern
fun
{a:t@ype}
htuple2_get_at
(htuple2(a), natLt(2)): a
//
overload [] with htuple2_get_at
//
(* ****** ****** *)
local
assume
htuple2(a:t@ype) = @(a, a)
in
implement
{a}
htuple2_make(x, y) = @(x, y)
implement
{a}
htuple2_get_at
(xy, i) =
(
if i = 0 then xy.0 else xy.1
)
end // end of [local]
implement
main0() =
{
val xy = htuple2_make<int>(0, 1)
val () = println! ("xy[0] = ", xy[0])
val () = println! ("xy[1] = ", xy[1])
}
(* ****** ****** *)
On Wednesday, October 25, 2017 at 7:12:22 AM UTC-4, Russoul wrote:
>
> Is it possible to return array by value?
--
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 [email protected].
To post to this group, send email to [email protected].
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/a1c0346a-1c66-4073-b9aa-284757766289%40googlegroups.com.