rs
第一节中的定义有什么问题?
palindrome :: [a] -> [a] palindrome xs = con xs rs where con a b = rev (rev a []) b rs = rev xs -- here where rev [] rs = rs rev (x:xs) rs = rev xs (x:rs)
我只是在学习Haskell,但它的语法规则让我很困惑.错误消息是
[1 of 1] Compiling Main ( pelindrome.hs, interpreted ) pelindrome.hs:5:8: parse error on input `rs'
Johannes Sch.. 13
你的缩进是错的,我认为你只能where
在那里有一个(我可能非常错.我不是一个哈克尔家伙).对于rev
(空列表)的调用还缺少一个参数:
palindrome :: [a] -> [a] palindrome xs = con xs rs where con a b = rev (rev a []) b rs = rev xs [] -- here rev [] rs = rs rev (x:xs) rs = rev xs (x:rs) main = print (palindrome "hello")
打印出来:
"helloolleh"
我现在要尝试理解它.无论如何,玩得开心!
编辑:现在对我很有意义.我认为这是正确的版本.对于Haskell缩进规则,请阅读Haskell Indentation
你的缩进是错的,我认为你只能where
在那里有一个(我可能非常错.我不是一个哈克尔家伙).对于rev
(空列表)的调用还缺少一个参数:
palindrome :: [a] -> [a] palindrome xs = con xs rs where con a b = rev (rev a []) b rs = rev xs [] -- here rev [] rs = rs rev (x:xs) rs = rev xs (x:rs) main = print (palindrome "hello")
打印出来:
"helloolleh"
我现在要尝试理解它.无论如何,玩得开心!
编辑:现在对我很有意义.我认为这是正确的版本.对于Haskell缩进规则,请阅读Haskell Indentation