开发者

Haskell let in/where and if indentation

I have a function:

isSimpleNumber :: Int -> Bool
isSimpleNumber x = let deriveList = map (\y -> (x `mod` y)) [1 .. x]
                       filterLength = length ( filter (\z -> z == 0) deriveList
                       ....

After filterLength i want to check how much filterLength, i try:

isSimpleNumber :: Int -> Bool
isSimpleNumber x = let开发者_高级运维 deriveList = map (\y -> (x `mod` y)) [1 .. x]
                       filterLength = length ( filter (\z -> z == 0) deriveList
                       in if filterLength == 2
                          then true

I get error:

    parse error (possibly incorrect indentation)
Failed, modules loaded: none.

How can i put indentation correctly with if and in?

Thank you.


This will compile:

isSimpleNumber :: Int -> Bool
isSimpleNumber x = let deriveList = map (\y -> (x `mod` y)) [1 .. x]
                       filterLength = length ( filter (\z -> z == 0) deriveList )
                   in filterLength == 2

main = print $ isSimpleNumber 5

There was a missing closing ")" after "deriveList". You don't need an if-then-true expression, also.


An if needs always both a then and an else branch, so you probably need if filterLength == 2 then true else false, which is equivalent to filterLength == 2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜