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])
}
(* ****** ****** *)