
Have you heard of Djinn?
https://hackage.haskell.org/package/djinn
If you punch in the signature of the combine function you're looking for
(rewritten more usefully in Kleisli composition form):
(Int -> (Integer->r) -> r) ->
(Integer -> (String -> r) -> r) ->
(Int -> (String -> r) -> r)
you'll get your wish granted. Djinn will magically write combine for you.
It'll work even if you abstract over the concrete types of Int, Integer,
String.
You can popover to the haskell IRC to try it out on the djinn bot there if
installation is too much of a bother.
Best, Kim-Ee
On Saturday, August 6, 2016, martin
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 hardcoded:
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@haskell.org javascript:; http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-- -- Kim-Ee