[Haskell-beginners] Simple Continuation question

David McBride toad3k at gmail.com
Sat Jul 12 15:12:10 UTC 2014


It's because the type of f is not (String -> String) -> String

It is (String -> Identity String) -> Identity String

Do a replacement manually and you'll see that f has to be of type ->  ContT
String Identity String --> ContT (String -> Identity String) -> Identity
String)

You can see that in the error message Expected type: ContT String Identity
String, Actual type: ContT Char [] String.  The reason why it looks weird
is that it is assuming that your monad instead of being identity is [], and
that the r in "m r" must be a Char in order for that to work.  I'm not
really sure why it chose list, probably type defaulting rules.


On Sat, Jul 12, 2014 at 6:24 AM, martin <martin.drautzburg at web.de> wrote:

> Hello all,
>
> I just started trying to understand Continuations, but my very first
> exercise already left me mystified.
>
> import Control.Monad.Cont
>
> resultIs :: Int -> Cont String String
> resultIs i = ContT $ f
>         where
>             f :: (String -> a) -> a
>             f k = k ("result=" ++ show i)
>
> If resultIs returns a Cont String String, then f should be
> (String->String)->String, but that doesn't compile. Why is
> that so?
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140712/c2c58e4e/attachment.html>


More information about the Beginners mailing list