-j
What do you think of the idea of sum types *being* interfaces, as opposed to being something of their own?
Sum types, on the other hand, are completely different and orthogonal to the above, and I don't think I would characterize interfaces as sums, since the existential notion fits far better to the idea.
-j
There are some differences. For example, sum types have a limited and pre-defined set of possible concrete types (A, B, or C), whereas an interface type has an open membership.
Guys, I don't want to be rude but this question is about how sum types could be implemented in terms of interfaces.
I think I understood.- Isn't then a tagged union a way to implement existential types?- And as interfaces are conceptually a type-value pair, aren't they basically a glorified tagged union?If the answer to both answers is yes, then that reinforces the notion that interfaces are sum types.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
That got me thinking: aren't interfaces our sum type? Given static, AOT compilation, and implicit interface implementation. If I wanted to express "A or B" (where A and B are types), I just need to have A and B implement one method in common, which no other type implements (a dummy, unexported one).
How would, for example, the precise GC handle non-tagged unions with fields of different pointer types?Not well. A concurrent GC is the real problem. If the implementation of union were a discriminator word followed by different kinds of memory based on the discriminator, a concurrent GC would need some way to read that whole piece of memory atomically, so that it got a consistent snapshot. Otherwise, even GC'ing a race-free single-goroutine program, the GC might misinterpret a float64 as an interface{} and crash the machine.
-j
-j
On Thu, Feb 18, 2016 at 9:09 AM, Jan Mercl <0xj...@gmail.com> wrote:On Thu, Feb 18, 2016 at 3:04 PM Manlio Perillo <manlio....@gmail.com> wrote:
> type Foo union {
> int
> float64
> Bar
> interface{}
> }How would, for example, the precise GC handle non-tagged unions with fields of different pointer types?Not well. A concurrent GC is the real problem. If the implementation of union were a discriminator word followed by different kinds of memory based on the discriminator, a concurrent GC would need some way to read that whole piece of memory atomically, so that it got a consistent snapshot. Otherwise, even GC'ing a race-free single-goroutine program, the GC might misinterpret a float64 as an interface{} and crash the machine.