It only requires type annotations on your uses of empty (as that is the only way to construct a collection). The phantom type sticks to everything after that.<br>If you don&#39;t care to add a signature then things still work just fine, you just won&#39;t be prevented from using indexes from the wrong collection if the the collection type is the same. I think this is nice, because if you are working with just one collection, or collections of only different types you probably don&#39;t want to care about the phantom type.<br>
But if you do care, it adds extra protection.<br><br>For example:<br><br>data P1<br>data P2<br><br>to = runState<br>inCol = evalState<br><br>a = empty :: IndexedCollection Int P1<br>b = empty :: IndexedCollection Int P2<br>
<br>(i1, a&#39;) = add 5 `to` a<br>(i2, b&#39;) = add 16 `to` b<br><br>test = lookup i2 `inCol` a&#39; -- type error, but type checks if no signatures on a or b<br><br>- Job<br><br><div class="gmail_quote">On Fri, Aug 21, 2009 at 12:24 PM, Sebastian Fischer <span dir="ltr">&lt;<a href="mailto:sebf@informatik.uni-kiel.de">sebf@informatik.uni-kiel.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="im"><br>
On Aug 21, 2009, at 5:11 PM, Job Vranish wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I also added an extra phantom type parameter to the collection (and key) so that I can prevent keys from being used on different collections even if they hold elements of the same type.<br>
</blockquote>
<br>
<br></div>
I have the impression that this requires explicit type annotations with your current solution which seems a bit tiresome. If not instantiated to specific different types, the additional phantom types of different collections can just be unified which does not lead to a type error.<br>

<br>
As you seem to implement a monadic interface, you might be able to steal the idea of using higher-rank polymorphism (that is used in the ST monad implementation) to ensure that the phantom types of different collections cannot be unified. But that would probably mean to implement your own monad that carries this phantom type too..<br>

<br>
Cheers,<br><font color="#888888">
Sebastian</font><div><div></div><div class="h5"><br>
<br>
-- <br>
Underestimating the novelty of the future is a time-honored tradition.<br>
(D.G.)<br>
<br>
<br>
<br>
</div></div></blockquote></div><br>