当我尝试使用下面的函数来实现像下面这样的函数时,编译器返回
解析错误(可能不正确的缩进或不匹配的括号)
功能:
演示 8 [1,2,3] 应该返回 [1,2,3,1,2,3,1,2]
demo :: Int -> [a] -> [a]
let n = 0
demo arg [] = []
demo arg (x:xs) =
if arg <= length (x:xs) then
take arg (x:xs)
else
let (x:xs) = (x:xs) ++ (x:xs)!!n
arg = arg - 1
n = n + 1
demo arg (x:xs)
Run Code Online (Sandbox Code Playgroud)
我该如何纠正?问候!
haskell ×1