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:
may it help other people with this problem ^_^