haskell - Using do notation with if/else -


i'm trying use do notation return list element if it's even:

ghci> { x <- [1,2,3]; if (even x) [x] else []} <interactive>:43:36: parse error on input `else' 

what doing wrong?

in addition, please note if code non-idiomatic.

you forgot "then". also, i'm not sure monad this..

do { x <- [1,2,3]; if (even x) [x] else []} 

Popular posts from this blog