Note that there are some explanatory texts on larger screens.

plurals
  1. POHaskell version of yin-yang puzzle : Kind incompatibility error
    primarykey
    data
    text
    <p>I want to implement the <a href="https://stackoverflow.com/questions/9250474/does-the-yin-yang-continuations-puzzle-make-sense-in-a-typed-language">yin-yang puzzle</a> in Haskell. Here is my attempt (unsucceful):</p> <pre><code>-- The data type in use is recursive, so we must have a newtype defined newtype Cl m = Cl { goOn :: MonadCont m =&gt; Cl m -&gt; m (Cl m) } yinyang :: (MonadIO m, MonadCont m) =&gt; m (Cl m) yinyang = do yin &lt;- (callCC $ \k -&gt; return (Cl k)) &gt;&gt;= (\c -&gt; liftIO (putStr "@") &gt;&gt; goOn c) yang &lt;- (callCC $ \k -&gt; return (Cl k)) &gt;&gt;= (\c -&gt; liftIO (putStr "*") &gt;&gt; goOn c) goOn yin yang </code></pre> <p>When look at the types, obviously <code>callCC $ \k -&gt; return (Cl k)</code> gives a <code>m (Cl m)</code>, so <code>yin</code> is of type <code>Cl m</code>. <code>yang</code> is the same thing. So I expect <code>goOn yin yang</code> gives the final type <code>m (Cl m)</code>.</p> <p>This implementation looks good, but the problem is it does not compile! here is the error I got:</p> <pre><code>Couldn't match kind `*' against `* -&gt; *' Kind incompatibility when matching types: m0 :: * -&gt; * Cl :: (* -&gt; *) -&gt; * In the first argument of `goOn', namely `yin' In a stmt of a 'do' block: goOn yin yang </code></pre> <p>Any idea to fix this?</p> <p><strong>UPDATE</strong></p> <p>Although I found the answer by myself, I still don't understand what that error message means. Can any one explain to me? What I know already is, in the problematic version, <code>goOn c</code> returns something like <code>Cl m -&gt; m (Cl m)</code>, not the expected <code>m (Cl m)</code>. But that is not what you can get from the error message.</p>
    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.
 

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