Working on a chess like move calculator in Haskell and I'm running in to a little problem for an assignment I'm forced to use Data.Array to save my pieces in with a Position defined by a Char and an Int. Now I have a list of pieces as input with writeToArray and I've tried a lot but I keep getting errors, does anyone know what I'm doing wrong?
Here is the code that it's about:
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)
And the error it gives:
Couldn't match expected type `Array Pos Piece' with actual type '[a0]'
All help is appreciated greatly
Fixed it!
changed the writeToArray function to this:
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)
may it help other people with this problem ^_^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With