2014-12-14 6 views
2

나는 목록의 모든 요소에 드로잉 기능을 매핑하려고합니다. 기능 자체는 drawMap는 좋아 보이지만 나는 그것을 사용할 때 다음과 같은 오류 얻을 : 지금은 함수가 반환하는 것을 함께 할 수있는 뭔가있어 이해 this을 읽는에서Haskell`[] '를`IO'와 일치시킬 수 없습니다

Couldn't match type `[]' with `IO' 
Expected type: IO (IO Bool) 
    Actual type: [IO Bool] 
In the return type of a call of `drawMap' 
In a stmt of a 'do' block: drawMap testMap 32 img screen 
In the second argument of `($)', namely 
    `do { screen <- SDL.setVideoMode 640 480 32 [SDL.SWSurface]; 
     img <- SDL.loadBMP "grass.bmp"; 
     drawMap testMap 32 img screen; 
     SDL.flip screen; 
     .... }' 

을,하지만 난있어 그 순간을 어떻게 고쳐야할지 모릅니다.

내 코드는 다음과 같습니다

drawMap tiles tilesize img dst = 
    mapM (drawTile tilesize img dst) tiles 

mapMControl.Monad에서입니다 :

testMap = [Tile 0 0 1, Tile 0 1 1, Tile 0 2 1, Tile 0 3 1] 

drawTile :: Int -> SDL.Surface -> SDL.Surface -> Tile -> IO Bool 
drawTile tilesize img dst tile = applySurface (tileX tile * tilesize) (tileY tile * tilesize) img dst 

drawMap :: [Tile] -> Int -> SDL.Surface -> SDL.Surface -> [IO Bool] 
drawMap tiles tilesize img dst = 
    map (drawTile tilesize img dst) tiles 

main :: IO() 
main = SDL.withInit [SDL.InitEverything] $ do 

    screen <- SDL.setVideoMode 640 480 32 [SDL.SWSurface] 

    img <- SDL.loadBMP "grass.bmp" 

    --drawTile 32 img screen (testMap !! 1) 
    drawMap testMap 32 img screen 

    SDL.flip screen 

    mainLoop 

답변

7

내가 원하는 생각합니다. drawMap의 유형이된다 :

drawMap :: [Tile] -> Int -> SDL.Surface -> SDL.Surface -> IO [Bool] 

그것이 BOOL의 목록이 아니라 IO 작업의 목록을 돌아가는 IO 작업입니다 즉.

+0

고맙습니다. @ user5402. mapM이 문제를 해결했습니다. – user3638162

관련 문제