[Haskell-cafe] Creating a list with do notation

Lucas Paul reilithion at gmail.com
Fri Jan 23 04:24:50 UTC 2015


Yes, but it might not work quite the way you expect:

Prelude> do { a <- [1]; (a:[2]) }
[1,2]
Prelude> do { a <- [1]; b <- (a:[2]); (b:[3]) }
[1,3,2,3]

- Lucas Paul


On Thu, Jan 22, 2015 at 9:04 PM, Cody Goodman
<codygman.consulting at gmail.com> wrote:
> List is a monad, does that mean i can create a list with do notation?
>
> My intuition led me to believe this would work:
>
> main = do
>   x <- return $ do
>     1
>     2
>     3
>   print (x :: [Int])
>
>
> However it didn't. Is this possible?
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list