我一直在嘗試解決一個練習問題,在該問題中我必須創建一個函式,該函式將特定數字從左向右旋轉,如下所示:
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)))
它給了我最后一次讀取功能的錯誤。
Parse error: module header, import declaration
or top-level declaration expected.
|
1 | (rotate (drop keeper (show n))) (take keeper (show n))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
提前致謝!
uj5u.com熱心網友回復:
您不小心將代碼從您在此處發布的內容的末尾復制并粘貼到了檔案的開頭。向上滾動并洗掉它,你應該很高興。您將有一兩個錯誤要修復,但從我在這里看到的情況來看,您將能夠勝任。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/450922.html
標籤:哈斯克尔
上一篇:自定義ListviewsetonItemClickListner在DialogFragment中使用kotlin中的Viewbinding不起作用
