I suddenly recall a feature in ATS:

$extype_struct.

The following code should compile and run:

#include "share/atspre_staload.hats"
#include "share/atspre_define.hats"

staload UN = "prelude/SATS/unsafe.sats"

datavtype message =
  | Bar of (int, double)
  | Baz of (double, double)

vtypedef
BAR = Bar_pstruct(int, double)
vtypedef
BAZ = Baz_pstruct(double, double)

extern vtypedef "BAR" = BAR
extern vtypedef "BAZ" = BAZ

typedef BAR_ =
$extype_struct "BAR_" of { contag=int }
typedef BAZ_ =
$extype_struct "BAZ_" of { contag=int }

extern castfn stack_unwind{a:vt0p}(INV(a)):<> void

fn f(x: !message): void =
  case+ x of
  | Bar(a,b) => println!("BAR ", a, " ", b)
  | Baz(a,b) => println!("BAZ ", a, " ", b)

implement main0() =
  let
    var b : BAR_
    val () = b.contag := 0
    val p = $UN.castvwtp0{BAR}(addr@b)
    val msg = $UN.castvwtp0{message}(addr@b)
    val Bar(x,y) = p
    val () = begin
      x := 5;
      y := 3.14;
      f(msg)
    end
    val _ = $UN.castvwtp0{ptr}((view@x, view@y | p))
  in
    stack_unwind(msg)
  end

On Wednesday, March 21, 2018 at 4:49:02 PM UTC-4, gmhwxi wrote:
>
>
> The tag part needs to be set manually. For Bar, it is 0. For Baz, it is 1.
> You may have to do it in C or in unsafe ATS for this part.
>
>
>
> On Wed, Mar 21, 2018 at 4:32 PM, Andrew Knapp <...> wrote:
>
>> The code on glot also fails if you change Bar to Baz in all the 
>> appropriate places.
>>
>> -- 
>> 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-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to ats-lang-users@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/55f6d7ff-167d-4a96-be75-5761dbf88908%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ats-lang-users/55f6d7ff-167d-4a96-be75-5761dbf88908%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>

-- 
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-users+unsubscr...@googlegroups.com.
To post to this group, send email to ats-lang-users@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/9857dcaa-b679-4305-bb3a-f70b56b9c5be%40googlegroups.com.

Reply via email to