[Haskell-beginners] My Continuation doesn't typecheck
toad3k at gmail.com
Sat Aug 6 17:01:00 UTC 2016
The only way to do this is to do it step by step.
combine :: t1 -> (t1 -> t2 -> t) -> t2 -> t
>:t combine 9
combine 9 :: Num t1 => (t1 -> t2 -> t) -> t2 -> t
f1 :: Int -> (Integer -> r) -> r
>:t combine 9 f1
combine 9 f1 :: (Integer -> t) -> t
f2 :: Integer -> (String -> r) -> r
>:t combine 9 f1 f2
combine 9 f1 f2 :: (String -> r) -> r
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.
On Sat, Aug 6, 2016 at 4:03 AM, martin <martin.drautzburg at web.de> wrote:
> Hello all,
> in order to gain some intuition about continuations, I tried the following:
> -- two functions accepting a continuation
> f1 :: Int -> (Integer->r) -> r
> f1 a c = c $ fromIntegral (a+1)
> f2 :: Integer -> (String -> r) -> r
> f2 b c = c $ show b
> -- combine the two functions into a single one
> run1 :: Int -> (String -> r) -> r
> run1 a = f1 a f2
> -- *Main> run1 9 id
> -- "10"
> So far so good.
> Then I tried to write a general combinator, which does not have f1 and f2
> combine a f g = f a g
> -- This also works
> -- *Main> combine 9 f1 f2 id
> -- "10"
> What confuses me is the the type of combine. I thought it should be
> combine :: Int ->
> (Int -> (Integer->r) -> r) -> -- f1
> (Integer -> (String -> r) -> r) -> -- f2
> ((String -> r) -> r)
> but that doesn't typecheck:
> Couldn't match expected type ‘(String -> r) -> r’
> with actual type ‘r’
> Can you tell me where I am making a mistake?
> Beginners mailing list
> Beginners at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners