haskellfunctional-programminghaskell-stackhaskell-platformguard-statement

How to use let with guards in Haskell?


I'm trying to do the following in Haskell:

 someFunction :: [] -> Int
 someFunction list 
 let a
 | length list == 1 = 10
 | otherwise = 0
 b
 | length list == 1 = 10 
 | otherwise = 0
 in findValues (a+b)

So that the values of a and b will be dependent on the conditions in the guards being met or not. This syntax keeps giving me errors and I'm not sure why. Do I need to use a where clause or is there a correct "let" syntax to achieve what I want?

Thanks for any help


Solution

  • It's a bit hard to say, but I'm guessing you meant

    someFunction :: [] -> Int
    someFunction list =
      let a | length list == 1 = 10
            | otherwise = 0
          b | length list == 1 = 10 
            | otherwise = 0
      in findValues (a+b)