[Haskell-beginners] Simple Continuation question

martin martin.drautzburg at web.de
Sun Jul 13 06:44:04 UTC 2014


Yes, this works.

Is this because I was using the Cont monad transformer instead of a plain coninutation monad? And with a plain
continuation monad  (String -> String) -> String would have worked?

Does everybody use the transformer these days? Is a plain continuation monad still around?

Am 07/12/2014 05:12 PM, schrieb David McBride:
> 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 <mailto: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 <mailto:Beginners at haskell.org>
>     http://www.haskell.org/mailman/listinfo/beginners
> 
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
> 



More information about the Beginners mailing list