Use 'let' in 'if' expression

Posted by demas on Stack Overflow See other posts from Stack Overflow or by demas
Published on 2010-10-21T08:37:35Z Indexed on 2010/12/24 8:54 UTC
Read the original article Hit count: 237

Filed under:

I need a function that works like this:

foo :: Integer -> Integer -> [Integer]
foo a b = do
           let result = []
           let Coord x y = boo a b
           if x > 0
              let result = result ++ [3]
           if y > 0 
              let result = result ++ [5]
           if x < a
              let result = result ++ [7]
           if y < b
              let result = result ++ [9]
           result

I can not use the guards because the result can have more then one element. But as I see I can not use 'let' in the 'if' expression:

all_possible_combinations.hs:41:14: parse error on input `let'

How can I check multiple expressions and add new elements in the list? I search not only imperative solution, but the functional one.

© Stack Overflow or respective owner

Related posts about haskell