poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] A new mechanism to access the active field of unions


From: Dan Čermák
Subject: Re: [RFC] A new mechanism to access the active field of unions
Date: Fri, 05 Mar 2021 18:46:51 +0100

Hi Mohammad-Reza,

Mohammad-Reza Nabipoor via poke-devel <poke-devel@gnu.org> writes:

[snip]
>
> More ideas?
>

I got a bit out of touch with the current state of the poke language,
but would match statements like in OCaml or Rust be out of the question?
For example in OCaml, you can define something like a C union as
follows:

type my_enum =
  | Byte of int
  | Vec of int * int * int
  | Empty


and then use match statements to find out which type was in an enum:

match e with
  | Empty -> "nothing"
  | Vec(x, y, z) -> x ^ ", " ^ y ^ ", " ^ z
  | Byte(x) -> x


Would something like this work for poke?


Cheers,

Dan

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]