加载此文件时出现此程序问题:
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move]
hanoi 0 _ _ _ = []
hanoi n a b c =
let
step1move = hanoi (n-1) a c b
step2move = (a,b)
step3move = hanoi (n-1) c b a
in
step1move ++ [step2move] ++ step3move`
hanoi4 :: Integer -> Peg -> Peg -> Peg -> Peg -> [Move]
hanoi4 0 _ _ _ _ = []
hanoi4 n a b c d =
let
(half1,half2) = segment n
step1 = hanoi4 half1 a c b d
step2 = hanoi half2 a d b
step3 = (a, b)
step4 = hanoi half2 d b a
step5 = hanoi4 half1 c b a d
in
step1 ++ step2 ++ [step3] ++ step4 ++ step5
-- Segment n into two "halves" such that half1 + half2 = n - 1
segment :: Integer -> (Integer, Integer)
segment n = let half1 = n div 2 in (half1, n half1=1)`
答案 0 :(得分:0)
我看到三个问题。首先,您的函数定义需要缩进。 (与大多数使用花括号和分号的C系列语言不同,Haskell的解析器使用空格来定义函数体和其他句法结构,如do-blocks。)所以代替:
hanoi n a b c =
let
...
你需要:
hanoi n a b c =
let
..
其次,你有两个迷失反引号(`)字符。
第三,你的segment
函数定义看起来好像有一些错误的字符:
-segment n = let half1 = n div 2 in (half1, n half1=1)`
+segment n = let half1 = n div 2 in (half1, n-half1-1)