<div dir="ltr"><div><div><div><div>The only way to do this is to do it step by step.<br></div>:t combine<br>combine :: t1 -> (t1 -> t2 -> t) -> t2 -> t<br><br></div>>:t combine 9<br>combine 9 :: Num t1 => (t1 -> t2 -> t) -> t2 -> t<br><br>>:t f1<br>f1 :: Int -> (Integer -> r) -> r<br>>:t combine 9 f1<br>combine 9 f1 :: (Integer -> t) -> t<br><br>>:t f2<br>f2 :: Integer -> (String -> r) -> r<br>>:t combine 9 f1 f2<br>combine 9 f1 f2 :: (String -> r) -> r<br><br></div>At some point the t2 in combine becomes a function, which causes the rest of the type to change. I feel like combine was meant to be something else, f (g a) or g (f a) or something else, but I'm not sure what.<br></div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Aug 6, 2016 at 4:03 AM, martin <span dir="ltr"><<a href="mailto:martin.drautzburg@web.de" target="_blank">martin.drautzburg@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all,<br>
<br>
in order to gain some intuition about continuations, I tried the following:<br>
<br>
-- two functions accepting a continuation<br>
<br>
f1 :: Int -> (Integer->r) -> r<br>
f1 a c = c $ fromIntegral (a+1)<br>
<br>
f2 :: Integer -> (String -> r) -> r<br>
f2 b c = c $ show b<br>
<br>
-- combine the two functions into a single one<br>
<br>
run1 :: Int -> (String -> r) -> r<br>
run1 a = f1 a f2<br>
<br>
<br>
-- *Main> run1 9 id<br>
-- "10"<br>
<br>
So far so good.<br>
<br>
<br>
Then I tried to write a general combinator, which does not have f1 and f2 hardcoded:<br>
<br>
combine a f g = f a g<br>
<br>
-- This also works<br>
<br>
-- *Main> combine 9 f1 f2 id<br>
-- "10"<br>
<br>
<br>
What confuses me is the the type of combine. I thought it should be<br>
<br>
combine :: Int -><br>
(Int -> (Integer->r) -> r) -> -- f1<br>
(Integer -> (String -> r) -> r) -> -- f2<br>
((String -> r) -> r)<br>
<br>
<br>
but that doesn't typecheck:<br>
<br>
Couldn't match expected type ‘(String -> r) -> r’<br>
with actual type ‘r’<br>
<br>
<br>
Can you tell me where I am making a mistake?<br>
<br>
______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>