Note that there are some explanatory texts on larger screens.

plurals
  1. POhaskell -- not understanding why this associated type example needs more inference
    primarykey
    data
    text
    <p>Consider the following code,</p> <pre><code>data MyBaseExpr α where ConstE :: Show α =&gt; α -&gt; MyBaseExpr α class Monad =&gt; MyMonadCls where type ExprTyp :: * -&gt; * var :: String -&gt; ExprTyp α -&gt; (ExprTyp α) expTypArg :: forall α. MyMonadCls =&gt; ExprTyp α -&gt; α expTypArg a = undefined -- dummy type which will be used as an instance newtype A α = A ( α) </code></pre> <p>Then, if one tries to write an instance using the expTypeArg function,</p> <pre><code>instance forall . (Monad , Monad (A )) =&gt; MyMonadCls (A ) where type ExprTyp (A ) = MyBaseExpr var nme init@(expTypArg -&gt; typb) = return init </code></pre> <p>the compiler complains</p> <pre><code>Couldn't match type `ExprTyp 0' with `MyBaseExpr' Expected type: ExprTyp (A ) α Actual type: ExprTyp 0 α </code></pre> <p>But, if one adds some scoped type expressions,</p> <pre><code>instance forall . (Monad , Monad (A )) =&gt; MyMonadCls (A ) where type ExprTyp (A ) = MyBaseExpr var nme init@((expTypArg :: MyMonadCls (A ) =&gt; ExprTyp (A ) α -&gt; (A α)) -&gt; typb) = return init </code></pre> <p>then it resolves fine. What's the problem resolving <code>ExprTyp == MyBaseExpr</code> for <code>expTypArg</code>?</p> <h2>edit</h2> <p>Thanks very much, Daniel! Here's a way to take some of the verbage out, after noticing that only the type of <code></code> need be enforced.</p> <pre><code>ignore_comp :: α -&gt; β -&gt; β ignore_comp a b = b instance forall . (Monad , Monad (A )) =&gt; MyMonadCls (A ) where type ExprTyp (A ) = MyBaseExpr var nme init@(expTypArg -&gt; typb) = typb `ignore_comp` return init </code></pre>
    singulars
    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.
    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