Haskell 让/在哪里以及是否缩进
我有一个函数:
isSimpleNumber :: Int -> Bool
isSimpleNumber x = let deriveList = map (\y -> (x `mod` y)) [1 .. x]
filterLength = length ( filter (\z -> z == 0) deriveList
....
在filterLength之后我想检查多少filterLength,我尝试:
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
我收到错误:
parse error (possibly incorrect indentation)
Failed, modules loaded: none.
如何使用if和in正确放置缩进?
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将编译:
“deriveList”之后缺少结束符“)”。您也不需要 if-then-true 表达式。
This will compile:
There was a missing closing ")" after "deriveList". You don't need an if-then-true expression, also.
if
始终需要then
和else
分支,因此您可能需要if filterLength == 2 then true else false< /code>,相当于
filterLength == 2
。An
if
needs always both athen
and anelse
branch, so you probably needif filterLength == 2 then true else false
, which is equivalent tofilterLength == 2
.