如何合并使用 show in Haskell 创建的两个列表?

How to combine two lists created with show in Haskell?

我一直在尝试解决一个练习题,在这个练习题中我必须创建一个函数来将特定数字从左向右旋转,如下所示:

print $ digRotator 68957 2 == 68579
print $ digRotator 68579 3 == 68597

第一个参数是数字,第二个是目标数字之前保存的数字。在第一个中它是 2 所以 6 和 8 被保存并且 9 被旋转。 到目前为止我试过这个:

rotate :: [a] -> [a]
rotate [] = []
rotate (a:as) = as ++ [a]

digRotator :: Int -> Int -> Int
digRotator n keeper
  | keeper == 0 = (read . rotate . show) n
  | otherwise = read ((rotate (drop keeper (show n))) ++ (take keeper (show n)))

最后一个 read 函数给我错误。

Parse error: module header, import declaration
    or top-level declaration expected.
  |
1 | (rotate (drop keeper (show n))) ++ (take keeper (show n))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

提前致谢!

您不小心将此处发布的代码末尾的代码复制并粘贴到了文件的开头。向上滚动并删除它,你就可以开始了。您将有一两个错误需要修复,但从我在这里看到的情况来看,您将完全有能力解决它。