News for hackers. Stuff that matters.
Re:Pony is an open-source, actor-model, high performance pro... by tonyg on Thursday January 14, 2016 @03:40PM (#10904307)
They're both sums, but Pony (and e.g. Typed Racket) has unlabelled unions, while Haskell/ML have labelled unions. Pony's (X | None) is not like Haskell's Maybe X in that in Haskell, X could be unit, while in Pony that would collapse the type to just None. In other words, in Haskell, Maybe (Maybe X) makes sense; in Pony and Typed Racket, it doesn't.
Re:Pony is an open-source, actor-model, high performance pro... by steveklabnik on Thursday January 14, 2016 @04:04PM (#10904461)
Yet another terminology issue: do you mean tagged vs untagged? IE, there's an extra field for the discriminant. Or rather, Pony does _not_ have a discriminant, but Haskell/ML do?

(I am 99% sure that's what you mean, but since I already screwed up terms once in this thread...)

Re:Pony is an open-source, actor-model, high performance pro... by tonyg on Sunday January 17, 2016 @01:00PM (#10920222)
That's roughly it. I was referring to a difference at the type system level, rather than the runtime level, though.

Disjoint unions aka sum types (as seen in Haskell/ML etc) entail some runtime way of keeping track which side of the sum any given inhabitant lies on. Tags are one way to do this, but e.g. in a language where pointers/references are never the zero machine word, and unit is represented as the zero word, no tag would be needed for the type Maybe String.

Union types (as seen in Pony, apparently, and also in Typed Racket), by contrast, /don't/ preserve information about which side of the union an inhabitant came from.

So, disjoint types: A + A ≠ A but union types: A ∪ A = A

So expanding (Maybe X) into (X + 1), we have that (Maybe (Maybe X)) = ((X + 1) + 1) ≠ X + 1,

but if instead (Maybe X) expands to (X ∪ 1), we have that (Maybe (Maybe X)) = ((X ∪ 1) ∪ 1) = X ∪ 1 = (Maybe X).

This is one of the problems with uses of null in languages that have it.