Phantom types are used frequently in Haskell to really great effect. Perhaps the most well-known example is the ST monad which allows you to do mutable, destructive updates in a "pure" fashion by containing them all within a narrow region. From outside of that region, the effects are invisible and referentially transparent. This is great for embedding your favorite iterative/mutable algorithm in a pure program.<p>Phantom types along with quantified type erasure allow the compiler to force these impure regions to be contained. They disallow sharing of variables or results between ST monad invocations statically.<p>To do so, most operations are polymorphic in the phantom variable. So something like `get (put x box)` is of type `ST s Int` for an `x :: Int`. The `s` corresponds to whichever ST region this action gets run within.<p>Running ST looks like `runST :: (forall s. ST s a) -> a` which means that the ST action you give to ST must be completely naive in its choice of region. Another way of thinking about it is that the `s` parameter is chosen adversarially by the compiler so that only ST actions which are able to be run in any region are allowed to be run at all.
I loved this blog. BluishCoder was my goto for Factor articles when I was learning about Factor. At least I thought it was. Browsing the titles under the Factor tag, I don't find one article I recognize, and all of the links I've tried clicking through wind up at nginx 404.<p>Sadly! Books and their covers... I'm sure they were good.<p>I did find the article I was thinking of, but today keyword search has failed me. I was looking for "monotonically increasing timers" and the correct search was "fast now"<p><a href="http://re-factor.blogspot.com/2011/03/fast-now.html" rel="nofollow">http://re-factor.blogspot.com/2011/03/fast-now.html</a><p>Chris D, are you here reading comments? Can you bring back your Factor articles?
(I don't know Rust)<p>So I assume the compiler infers the type of `TI(1)` as `T<int>` and `TS(~"Hello")` as `T<~string>` because ...?<p>What if you defined:<p><pre><code> enum T<A> {
TX(int, ~string),
TY(~string, int)
}
</code></pre>
What's the inferred type of `TX(1, ~"a")`?
How does the compiler know that TI(1) is of type T<int>, and TS("foobar") is T<~string>? Does it infer the type of the enum constructors from their arguments? Does that mean the arities must be the same?<p>Say something like:<p>enum Node<A> {
StringNode(Node, Node, ~string)
IntNode(Node, Node, int)
VoidNode(Node, Node)
}<p>Is there any way of declaring that StringNode gives you Node<~string>, and IntNode gives Node<int>?