Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursive Type Families
    primarykey
    data
    text
    <p>I am experimenting with an <code>mtl</code>-style class that allows me to lift <code>Pipe</code> composition over an outer monad. To do so, I must define which two variables of the type are the domain and codomain of <code>Pipe</code> composition.</p> <p>I tried using an associated type family approach, but to no avail:</p> <pre><code>{-# LANGUAGE TypeFamilies #-} import Control.Monad.Trans.Free import Control.Monad.Trans.State import Control.Pipe hiding (Pipe) data Pipe a b m r = Pipe { unPipe :: FreeT (PipeF a b) m r } class MonadPipe m where type C a b (m :: * -&gt; *) :: * -&gt; * idT :: C a a m r (&lt;-&lt;) :: C b c m r -&gt; C a b m r -&gt; C a c m r instance (Monad m) =&gt; MonadPipe (Pipe i o m) where type C a b (Pipe i o m) = Pipe a b m idT = Pipe idP (Pipe p1) &lt;-&lt; (Pipe p2) = Pipe (p1 &lt;+&lt; p2) instance (MonadPipe m) =&gt; MonadPipe (StateT s m) where type C a b (StateT s m) = StateT s (C a b m) idT = StateT $ \s -&gt; idT (StateT f1) &lt;-&lt; (StateT f2) = StateT $ \s -&gt; f1 s &lt;-&lt; f2 s </code></pre> <p>However, the above code does not type-check. GHC gives the following errors:</p> <pre><code>family.hs:23:15: Could not deduce (C a a m ~ C a0 a0 m0) from the context (MonadPipe m) bound by the instance declaration at family.hs:21:14-52 NB: `C' is a type function, and may not be injective Expected type: C a a (StateT s m) r Actual type: StateT s (C a0 a0 m0) r In the expression: StateT $ \ s -&gt; idT In an equation for `idT': idT = StateT $ \ s -&gt; idT In the instance declaration for `MonadPipe (StateT s m)' family.hs:24:10: Could not deduce (C b c m ~ C b0 c0 m1) from the context (MonadPipe m) bound by the instance declaration at family.hs:21:14-52 NB: `C' is a type function, and may not be injective Expected type: C b c (StateT s m) r Actual type: StateT s (C b0 c0 m1) r In the pattern: StateT f1 In an equation for `&lt;-&lt;': (StateT f1) &lt;-&lt; (StateT f2) = StateT $ \ s -&gt; f1 s &lt;-&lt; f2 s In the instance declaration for `MonadPipe (StateT s m)' &lt;&lt;Two other errors for 'C a b m' and 'C a c m'&gt;&gt; </code></pre> <p>It's hard for me to understand why the types won't unify, especially for the <code>idT</code> definition, since I'd expect the inner <code>idT</code> to be universally quantified over <code>a</code> so it would match the outer one.</p> <p>So my question is whether this is implementable with type families, and if not possible with type families, how could it be implemented?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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