Are there documentation on constraints being types, how they can be declared/handled and what are the interests?<br><br><div class="gmail_quote">2012/2/7 Mikhail Vorozhtsov <span dir="ltr">&lt;<a href="mailto:mikhail.vorozhtsov@gmail.com">mikhail.vorozhtsov@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 02/06/2012 03:32 AM, Gábor Lehel wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There&#39;s a common pattern in Haskell of writing:<br>
<br>
data E where E :: C a =&gt;  a -&gt;  E<br>
also written<br>
data E = forall a. C a =&gt;  E a<br>
<br>
I recently uploaded a package to Hackage which uses the new<br>
ConstraintKinds extension to factor this pattern out into an Exists<br>
type parameterized on the constraint, and also for an Existential type<br>
class which can encompass these kind of types:<br>
<br>
<a href="http://hackage.haskell.org/package/exists" target="_blank">http://hackage.haskell.org/<u></u>package/exists</a><br>
<br>
My motivation was mostly to play with my new toys, if it turns out to<br>
be useful for anything that&#39;s a happy and unexpected bonus.<br>
<br>
Some interesting things I stumbled upon while writing it:<br>
<br>
</blockquote></div>
[snip]<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
- One of the advantages FunctionalDependencies has over TypeFamilies<br>
is that type signatures using them tend to be more readable and<br>
concise than ones which have to write out explicit equality<br>
constraints. For example, foo :: MonadState s m =&gt;  s -&gt;  m () is nicer<br>
than foo :: (MonadState m, State m ~ s) =&gt;  s -&gt;  m (). But with<br>
equality superclass constraints (as of GHC 7.2), it&#39;s possible to<br>
translate from TF-form to FD-form (but not the reverse, as far as I<br>
know): class (MonadStateTF m, s ~ State m) =&gt;  MonadStateFDish s m;<br>
instance (MonadStateTF m, s ~ State m) =&gt;  MonadStateFDish s m.<br>
</blockquote></div>
Even better, you can write<br>
<br>
type ExistentialWith c e = (Existential e, c ~ ConstraintOf e)<br>
<br>
instead of<br>
<br>
class    (Existential e, c ~ ConstraintOf e) =&gt; ExistentialWith c e<br>
instance (Existential e, c ~ ConstraintOf e) =&gt; ExistentialWith c e<br>
<br>
and drop UndecidableInstances.<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
______________________________<u></u>_________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/<u></u>mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br>