我是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'
请给我一个提示
我是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'
请给我一个提示
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
正如@wit 所指出的,where应该在表达式的末尾使用。为什么?因为:
let;如果你想定义一个别名fronthand,你应该使用let表达式。
有关它们的差异和优势的更多信息,请参阅Let vs. Where。