2012-10-21 45 views
2

像在Haskell移動計算國際象棋的工作和我的一個分配給一個小問題 運行在我被迫在使用Data.Array救我的作品與確定的位置一個Char和一個Int。現在我有個輸入與writeToArray的名單,我已經嘗試了很多,但我不斷收到錯誤,沒有人知道我在做什麼錯?哈斯克爾列表爲Array

這裏是它的有關代碼:

data Squares = Squares {array :: Array Pos Piece} 
data Pos = Pos Char Int deriving (Eq, Ord, Ix) 
data Piece = Piece { piecetype :: PieceType, color :: PieceColor } | Empty 

writeToArray :: [Piece] ->(Array Pos Piece) 
writeToArray (x:xs) = (((Pos 'a' 1), (Pos 'h' 8)) [((Pos char int), x) | char <- ['a'..'h'], int <- [1..8]])` : writeToArray (xs) 

和錯誤它給:

Couldn't match expected type `Array Pos Piece' with actual type '[a0]' 

所有幫助是極大的讚賞

+0

結果類型是一個列表。 – arrowd

回答

3

定了!

改變了writeToArray功能如下:

writeToArray :: [Piece] ->(Array Pos Piece) 
writeToArray list = Data.Array.array (Pos 'a' 1, Pos 'h' 8) (zip [(Pos char int)| char <- ['a'..'h'], int <- [1..8]] list) 

它可以幫助其他人解決這個問題^ _^writeToArray的