Remix.run Logo
jnpnj 3 days ago

Newb question, aren't phantom types and typestates a subset (or cousin) of linear types ?

burakemir 3 days ago | parent | next [-]

No. A phantom type is a type whose only use is to communicate a constraint on a type variable, without having a runtime value that corresponds to it.

Typestate is a bit closer: it communicates some property where an operation (typically a method invocation) changes the property and hence the typestate. But there isn't necessarily a mechanism that renders the value in the old typestate inaccessible. When there is, then this indeed requires some linearity/affinity ("consuming the object"), but typestate is something built "on top".

jnpnj 3 days ago | parent [-]

Thanks a lot

Twey 3 days ago | parent | prev [-]

Kind of! Specifically typestates allow you to encode the special case of linear functions `f a ⊸ f b` for some type constructor `f` where `a` and `b` are (usually?) phantom types. Phantom types themselves don't involve any linearity per se though.