<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 25 May 2015 at 23:12, Barry DeZonia <span dir="ltr"><<a href="mailto:bdezonia@gmail.com" target="_blank">bdezonia@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>I have a small piece of code that does not compile and I'm having trouble figuring out why.</div><div><br></div><div>Here is the relevant snippet:</div><div><br></div><div>readChunks :: Handle -> [String] -> IO [String]</div><div>readChunks handle accum = do</div><div> chunk <- readHeaderChunk handle</div><div> if isLast chunk</div><div> then return (accum ++ chunk)</div><div> else return (readChunks handle (accum ++ chunk))</div></div></blockquote><div> </div><div>In short, try: else readChunks handle (accum ++ chunk)</div><div><br></div><div>Explanation,</div><div><br></div><div>return :: a -> IO a (in this case)</div><div>readChunks handle (accum ++ chunk) :: IO [String]</div><div><br></div><div>therefore, return (readChunks handle (accum ++ chunk)) :: IO (IO [String])</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div><div>isLast :: [String] -> Bool</div></div><div><br></div><div><div>readHeaderChunk :: Handle -> IO [String]</div></div><div><br></div><div>And here is the single compiler error:</div><div><br></div><div><div>hacks.hs:48:18:</div><div> Couldn't match expected type `[String]'</div><div> with actual type `IO [String]'</div></div></div></blockquote><div> </div><div>Wanted [String], got IO [String] </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div> In the return type of a call of `readChunks'</div><div> In the first argument of `return', namely</div><div> `(readChunks handle (accum ++ chunk))'</div><div> In the expression: return (readChunks handle (accum ++ chunk))</div></div><div><br></div><div>What I'm most confused about is that chunk is passed to isLast as a [String] with no compiler error but cannot be passed to accum ++ chunk that way. Or so it seems. Can someone she some light on this? Thanks.</div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div></div>