Hacker News new | ask | show | jobs
by austinz 4161 days ago
Swift's Optional is just Maybe with some built-in sugar. Sum types are supported, with the caveat that the compiler is sort of broken when it comes to generics.

Personally, I just want higher-kinded types, and for the following code snippets to work as-is:

  enum Either<A,B> {
    case Left(A)
    case Right(B)
  }

  enum Tree<A> {
    case Leaf
    case Node(Tree<A>, A, Tree<A>)
  }
The first breaks because of the "Unimplemented non-fixed multi-payload enum layout" compiler error, and the second breaks because enums have value semantics. Both can be worked around in full generality by declaring a 'Box<T>' generic wrapper class, but that workaround is inelegant and cumbersome.