Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于可能缩进错误的Haskell错误_Haskell - Fatal编程技术网

关于可能缩进错误的Haskell错误

关于可能缩进错误的Haskell错误,haskell,Haskell,在下面的Hasekll代码中 func1 :: Int -> [Int] func1 m = aux 2 where aux h = | length (func2 h) >= m = take m (func2 h) | otherwise = aux (h + 100) GHC给出的误差为 parse error (possibly incorrect indentation or mismatched brackets)

在下面的Hasekll代码中

func1 :: Int -> [Int]
func1 m = aux 2
  where aux h = 
    | length (func2 h) >= m = take m (func2 h)
    | otherwise              = aux (h + 100)
GHC给出的误差为

    parse error (possibly incorrect indentation or mismatched brackets)
   |
15 |     | length (primes h) >= m = take m (primes h)
   |     ^

Compilation failed.

我没有使用制表符,而是始终使用两个空格进行缩进。我还手动重新键入了整个函数一次,以防在某个时候意外地混合了制表符和空格。然而,在阅读了大约半个小时缩进规则后,我仍然不知道这个错误来自何处。

与缩进无关-只需删除
=
。(这是第一次从Haskell开始使用guards时经常犯的错误-我记得犯过很多次!)你的意思是用
where aux h=
替换
where aux h
,对吗?我这样做了,但不知何故编译器仍然给出了相同的错误…是的,我是这个意思。如果仍然存在解析错误,您可以尝试使用防护装置缩进行,使其位于
aux
的右侧。您需要将其缩进到比
aux
的开头多至少一个字符的右侧。从
开始的列与缩进目的无关。重要的是
where
后面的单词开始的列,在您的情况下是
aux
aux
的定义缩进必须大于该列。