3 ms·
I don't know Haskell but this looks like Phantom Types in Scala. Can anyone who knows both languages enlighten us ? More on Scala Phantom types here https://
by theboywho 9y ago
I don't know Haskell but this looks like Phantom Types in Scala.
Can anyone who knows both languages enlighten us ?
More on Scala Phantom types here https://gigiigig.github.io/tlp-step-by-step/phantom-types.html https://gigiigig.github.io/tlp-step-by-step/phantom-types.ht...
- whateveracct 9y agodata State = Unbound | Bound | Listening | … data Socket (s :: State) (s :: State) is a phantom type, yes.
- yorwba 9y agoI don't know Scala, but Phantom Types look like they only encode the state at the type level, but don't prevent you from copying e.g. the closed door before opening it, which would be undesirable if the state transition corresponds to a side effect. Linear types can guarantee that the object participating in a state transition is not reused, which prevents accidentally referring to invalidated data.
- mcguire 9y agoThis, exactly. You can use phantom types to mark the difference between bound and unbound sockets, but you need the linear type system to prevent the unbound value from being used again.
- justinpombrio 9y agoYes, those are phantom types. Many languages allow phantom types --- basically any language that has type parameters. So Haskell as we've seen, Scala as you point out, ML, Rust, etc. That's not the interesting part, though. It's the linear types that are giving the guarantees here, and linear type systems are rare.