我是haskell的新手,试图完成一项小任务
get1th ( a , _, _ , _) = a
foo input =
where input = (a:_,b:_,c:_,d:_)
if ( length (get1th input) == 2 )
then permutations[2]
else permutations[3]
我收到错误说
parse error on input `where'
请给我一个提示
答案 0 :(得分:3)
where
子句必须写在最后:
foo input =
if ( length (get1th input) == 2 )
then permutations[2]
else permutations[3]
where (a:_,b:_,c:_,d:_) = input
已更新
还需要交换到(a:_,b:_,c:_,d:_) = input
,原因 - 我们要提取值,但不要重新定义input
答案 1 :(得分:1)
正如@wit指出的那样,where
应该在表达式的末尾使用。为什么?这是因为:
let
; 如果要正面定义别名,则应使用let
表达式。
有关它们的差异和优点的更多信息,请参阅Let vs. Where。