我对 Haskell 很陌生,目前对 monad 还没有很好的理解。我正在使用光泽来制作国际象棋。我面临的问题是加载多个图像。我正在使用loadBMP
haskell 提供的功能来加载图像。它的签名是:
loadBMP :: FilePath -> IO Picture
我可以加载单个图像,但无法加载图像数组。
-- This function calculates the path of all the images and then apply loadBMP function on it.
loadPieceImages :: [IO Picture]
loadPieceImages = do
map (loadBMP . (\n -> "images/" ++ n ++ ".bmp") . (\n -> if n < 6 then show n ++ "-w" else show (n `mod` 6) ++ "-b")) [0 .. 12]
main :: IO ()
main = do
images <- loadPieceImages -- On this line I am getting error.
play window (makeColor 1 0 0 1) 30 initialState draw transform (const id)
主要问题是我有[IO Picture]
类型,但我不知道如何将它变成[Picture]
.
这东西可能是非常基本的,但我现在无法理解单子。所以请解释你给出的答案。