title: Converting functions to CPS
body: <p>I have the following CPS implementation of <code>until</code>:</p>
  
  <pre><code>until' p f x cc = p x (\y -&gt; if y then cc(x)
                               else until' p f (f x (\z -&gt; cc(z))) cc)
  </code></pre>
  
  <p>Which type checks ok! Now, trying to CPS <code>map</code>:</p>
  
  <pre><code>map' f (x:xs) cc = f x (\y -&gt; map f xs (\ys -&gt; cc(y:ys)))
  </code></pre>
  
  <p>Another possible implementation:</p>
  
  <pre><code>map' f (x:xs) cc = cc(f x (\y cc' -&gt; map f xs (\ys -&gt; cc'(y:ys))))
  </code></pre>
  
  <p>However none of them type checks. Where am I doing the mistake? </p>
  
  <pre><code>    Couldn't match expected type ‘([a1] -&gt; t2) -&gt; t1’
                  with actual type ‘[(a1 -&gt; t1) -&gt; t]’
      Relevant bindings include
        y :: a1 (bound at test.hs:6:26)
        cc :: [a1] -&gt; t2 (bound at test.hs:6:15)
        f :: a -&gt; (a1 -&gt; t1) -&gt; t (bound at test.hs:6:6)
        map' :: (a -&gt; (a1 -&gt; t1) -&gt; t) -&gt; [a] -&gt; ([a1] -&gt; t2) -&gt; t
          (bound at test.hs:6:1)
      The function ‘map’ is applied to three arguments,
      but its type ‘(a -&gt; (a1 -&gt; t1) -&gt; t) -&gt; [a] -&gt; [(a1 -&gt; t1) -&gt; t]’
      has only two
      In the expression: map f xs (\ ys -&gt; cc (y : ys))
      In the second argument of ‘f’, namely
        ‘(\ y -&gt; map f xs (\ ys -&gt; cc (y : ys)))’
  Failed, modules loaded: none.
  </code></pre>