Note that there are some explanatory texts on larger screens.

plurals
  1. POFundeps for constraint families
    text
    copied!<p>A lot of constraints seem to come together. Let's abstract these away.</p> <pre><code>type MonadNumState a m = (MonadState a m, Num a) </code></pre> <p><code>MonadNumState</code> is just a constraint synonym, so I get the benefit of functional dependencies at every use, and can easily throw a <code>MonadNumState a m</code> into a context. Now, suppose I wish to abstract this into a constraint family:</p> <pre><code>class Iterator t where type MonadIter t a m :: Constraint next :: (MonadIter t a m) =&gt; m t ... instance Iterator Foo where type MonadIter Foo a m = (MonadState a m, Num a) ... instance Iterator Bar where type MonadIter Bar a m = (MonadRandom m, MonadSplit a m, RandomGen a) ... </code></pre> <p>But now <code>a</code> is not a functional dependency. <code>next</code> is virtually unusable since <code>a</code> cannot be inferred. What can I do? Well, I could, of course, use a type family instead. <code>MonadState</code> is written using fundeps, but it should be easy to convert the fundeps to type families.</p> <pre><code>instance (MonadState s m) =&gt; MonadStateFamily m where type St m = s get' = get ... instance (MonadStateFamily m) =&gt; MonadState (St m) m where get = get' ... </code></pre> <p>Guess not.</p> <pre><code>Foo.hs:25:3: The RHS of an associated type declaration mentions type variable `s' All such variables must be bound on the LHS </code></pre> <p>What else might I be able to do? What I really want is to existentially quantify away <code>s</code>. I've not found any way to do that without explicit dictionary passing.</p> <p>So, how do I get the benefit of fundeps for constraint families?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload