hello,
I would like to make a datastructure with a dataviewtype that could
possibly be referenced more than once and I don’t know if it is possible to
do this with linear types of ATS.
Basically I want to achieve this (this code doesn’t compile) :
#include “share/atspre_staload_tmpdef.hats”
staload UN = "prelude/SATS/unsafe.sats"
staload “prelude/SATS/reference.sats”
dataviewtype toto_vt =
Toto of (Strptr1, double)
| Titi of (double, Strptr1)
extern fun make_toto(i: double): toto_vt
extern fun print_toto(t: ref(toto_vt)): void
extern fun free_toto(t: toto_vt): void
implement make_toto(i) = if( i < 10.0 ) then
Toto(string0_copy(“hello”), i)
else
Titi(i, string0_copy(" world !"))
implement print_toto(t) = let
val tot: toto_vt = !t
val () = (case+ tot of
| Toto(s, x) => println!("TOTO -> ", s, ", ", x)
| Titi(x, s) => println!("TITI -> ", s, ", ", x) ): void
prval () = $UN.castview0{void}(tot)
in end
implement free_toto(t) = case+ t of
| ~Toto(s, x) => strptr_free s
| ~Titi(x, s) => strptr_free s
implement main0() = let
val t = make_toto(17.0)
val ref1 = ref<toto_vt>(t) //ref_make_viewptr(view@t, addr@t)
val ref2 = ref<toto_vt>(t) //ref_make_viewptr(view@t, addr@t)
val () = print_toto(ref1)
val () = print_toto(ref2)
in
free_toto t
end
I tried with reference, maybe I will have better fortune with pointer ?
Is it possible to do this in ATS ?
thanks a lot