Re:Sum Types in Go
by DaNmarner on Friday December 26, 2014 @03:25AM
(#8798450)
On a side note, Swift's enum provides complete support for sum type.
[ Parent
| on HN ]
They may not be recursive however
You can work around that using a "Box" type that wraps a value in a reference:
class Box<T> {
var contents : T
init(_ initialContents : T) {
contents = initialContents
}
}
enum BinaryTree {
case Leaf
case Branch(Box<BinaryTree>, Box<BinaryTree>)
}