<div dir="ltr"><div>Although a newtype has the same representation at runtime as the type inside, you still have to use the constructor as for a 'data' type.  This makes sense, as it is a <i>new type</i>, whose values must be distinguished from those of the inner type, and the only way to do that is if they are decorated with a constructor.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Sep 10, 2018 at 5:55 PM Rodrigo Stevaux <<a href="mailto:roehst@gmail.com">roehst@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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" target="_blank">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>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>