<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi, I was studying this post (<a href="http://www.haskellforall.com/2012/12/the-continuation-monad.html">http://www.haskellforall.com/2012/12/the-continuation-monad.html</a>) on CPS and I tried the following code:</div><div dir="ltr"><br></div><div dir="ltr"> module Main where <br></div><div dir="ltr"><br></div><div dir="ltr">
newtype Cont r a = Cont { runCont :: (a -> r) -> r } <br></div><div dir="ltr"><br></div><div dir="ltr"> onInput :: Cont (IO ()) String <br></div><div dir="ltr"> onInput f = do
s <- getLine <br></div><div dir="ltr"> f s
onInput f</div><div dir="ltr"><br></div><div dir="ltr">
main :: IO ()
main = onInput print <br></div><div dir="ltr"><br></div><div>I fails to compile:</div><div><br></div><div> "Couldn't match expected type ‘Cont (IO ()) String’
with actual type ‘(String -> IO a0) -> IO b0’
• The equation(s) for ‘onInput’ have one argument,
but its type ‘Cont (IO ()) String’ has none"</div><div><br></div><div>But I thought Cont a b would be expanded to (b -> a) -> a so that Cont (IO ()) String became (String -> IO ()) -> IO (), and if I give that type using `type` instead of `newtype`, it does type-check:</div><div><br></div><div> type Cont r a = (a -> r) -> r</div><div><br></div><div>What am I missing here about Haskell?</div><div><br></div><div>thanks folks!<br> </div></div></div></div>