Get two refs on same dataviewtype object

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 :wink:

See:

http://www.ats-lang.org/LIBRARY/libats/refcount.htmlOn Tuesday, October 15, 2013 1:49:58 PM UTC-4, Cyrille Duret wrote:

Let’s take the example of a scene management tree of a 3d engine where you
can find several references to the same geometry so I would like to do the
same here.
To have one instance of geometry and several references to it on another
data structure.

Indeed reference-counting might be the way for me. I will try it out.

thanks :wink:

Le mardi 15 octobre 2013 17:45:13 UTC+2, gmhwxi a écrit :

This cannot be done.
It is like wanting to put a physical object into distinct places.

Why not do

val ref2 = ref1

Or maybe you were thinking about reference-counting?

On Tuesday, October 15, 2013 3:23:44 AM UTC-4, Cyrille Duret wrote:

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 :wink:

thank you !Le mardi 15 octobre 2013 20:34:31 UTC+2, gmhwxi a écrit :

Some of the functions in

${PATSHOME}/contrib/libfloats/DATS/lamatrix.dats

makes use of refcnt.

On Tuesday, October 15, 2013 2:26:16 PM UTC-4, gmhwxi wrote:

See:

http://www.ats-lang.org/LIBRARY/libats/refcount.html

On Tuesday, October 15, 2013 1:49:58 PM UTC-4, Cyrille Duret wrote:

Let’s take the example of a scene management tree of a 3d engine where
you can find several references to the same geometry so I would like to do
the same here.
To have one instance of geometry and several references to it on another
data structure.

Indeed reference-counting might be the way for me. I will try it out.

thanks :wink:

Le mardi 15 octobre 2013 17:45:13 UTC+2, gmhwxi a écrit :

This cannot be done.
It is like wanting to put a physical object into distinct places.

Why not do

val ref2 = ref1

Or maybe you were thinking about reference-counting?

On Tuesday, October 15, 2013 3:23:44 AM UTC-4, Cyrille Duret wrote:

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 :wink:

This cannot be done.
It is like wanting to put a physical object into distinct places.

Why not do

val ref2 = ref1

Or maybe you were thinking about reference-counting?On Tuesday, October 15, 2013 3:23:44 AM UTC-4, Cyrille Duret wrote:

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 :wink:

Let’s take the example of a scene management tree of a 3d engine where you
can find several references to the same geometry so I would like to do the
same here.
To have one instance of geometry and several references to it on another
data structure.

Indeed reference-counting might be the way for me. I will try it out.

thanks ;-)Le mardi 15 octobre 2013 17:45:13 UTC+2, gmhwxi a écrit :

This cannot be done.
It is like wanting to put a physical object into distinct places.

Why not do

val ref2 = ref1

Or maybe you were thinking about reference-counting?

On Tuesday, October 15, 2013 3:23:44 AM UTC-4, Cyrille Duret wrote:

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 :wink:

Some of the functions in

${PATSHOME}/contrib/libfloats/DATS/lamatrix.dats

makes use of refcnt.On Tuesday, October 15, 2013 2:26:16 PM UTC-4, gmhwxi wrote:

See:

http://www.ats-lang.org/LIBRARY/libats/refcount.html

On Tuesday, October 15, 2013 1:49:58 PM UTC-4, Cyrille Duret wrote:

Let’s take the example of a scene management tree of a 3d engine where
you can find several references to the same geometry so I would like to do
the same here.
To have one instance of geometry and several references to it on another
data structure.

Indeed reference-counting might be the way for me. I will try it out.

thanks :wink:

Le mardi 15 octobre 2013 17:45:13 UTC+2, gmhwxi a écrit :

This cannot be done.
It is like wanting to put a physical object into distinct places.

Why not do

val ref2 = ref1

Or maybe you were thinking about reference-counting?

On Tuesday, October 15, 2013 3:23:44 AM UTC-4, Cyrille Duret wrote:

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 :wink: