<div dir="ltr"><div>The items in your do-block must be in the same monad as you're operating in - in this example - the list monad:</div><div><br></div><div><div>main = do</div><div>  x <- return $ do</div><div>    [ 1 ]</div><div>    [ 2 ]</div><div>    [ 3 ]</div><div>  print (x :: [Int])</div></div><div><br></div><div><br></div><div>Unfortunately, there is no accumulation of items. You can reason this out if you desugar the do-notation into binds:</div><div><br></div><div>[ 1 ] >> [ 2 ] >> [ 3 ]<br></div><div><br></div><div>[ 1 ] >>= (\x -> [ 2 ] >>= (\y -> [ 3 ]))<br></div><div><br></div><div>and then examine the list Monad instance.</div><div><br></div><div><br></div>You can achieve something similar to what you're looking for with the writer monad:<div><br></div><div><div>import Control.Monad.Writer.Lazy</div><div><br></div><div>main = do</div><div>  x <- return $ execWriter $ do</div><div>    tell [1]</div><div>    tell [2]</div><div>    tell [3]</div><div>  print (x :: [Int])</div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 23, 2015 at 3:04 PM, Cody Goodman <span dir="ltr"><<a href="mailto:codygman.consulting@gmail.com" target="_blank">codygman.consulting@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">List is a monad, does that mean i can create a list with do notation?<br><br>My intuition led me to believe this would work:<br><br>main = do<br>  x <- return $ do<br>    1<br>    2<br>    3<br>  print (x :: [Int])<br><br><br>However it didn't. Is this possible?<br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>