Haskell IO: Couldn't match type `IO' with `[]'

Darth_Vader721
playerInstruction :: [String] -> Int -> [String]
playerInstruction mapList count = do
    if count == 0
        then printf "First direction : "
        else printf "Next direction : "
    inp <- getLine
    case inp of
        "Up" -> instructionProc mapList Up
        "Down" -> instructionProc mapList Down
        "Left" -> instructionProc mapList Leftx
        "Right" -> instructionProc mapList Rightx
        otherwise -> playerInstruction mapList count

This is a part of the code of a project I am working on. This is a function to take in the player's instruction and redirect the player to another function. mapList is a list of String which supposed to contain the changes of the map step by step. count is the variable to count the number of instructions the player has input. The problem I am encountering is that the compiler is saying the line

inp <- getLine

having an error. With a message as stated in the topic. I am not sure how to fix this problem. Please feel free to see this link: Haskell IO: Reading the whole text file if you want to know more about this project. Thank you.

Ari Fordsham

You need to declare the function as IO in the signature:

playerInstruction :: [String] -> Int -> IO [String]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Haskell Couldn't match type `[]' with `IO'

Haskell: Error: Couldn't match type ‘[]’ with ‘IO’

Haskell - Couldn't match type [] with IO

"Couldn't match type `Maybe' with `IO' Expected type: IO String Actual type: Maybe String" In Haskell

Couldn't match expected type IO

Haskell readFile: Couldn't match expected type ‘[String]’ with actual type ‘IO String’

Software Transaction Memory in Haskell: Couldn't match expected type STM a0 with actual type IO ()

How to fix ''couldn't match expected type IO a0 with int'' in Haskell?

Couldn't match expected type ‘IO [String]’ with actual type ‘[String]’

Haskell powerset function - How to avoid Couldn't match expected type `IO t0' with actual type `[[Integer]]'

Haskell Couldn't match type

Haskell: Couldn't match type?

Haskell - Couldn't match type

Haskell: Couldn't match type ‘[Char]’ with ‘Text’

Haskell - Couldn't match type `[Char]' with `Char'

Haskell couldn't match weird expected type

Haskell: Couldn't match type `[Char]' with `Char'

Haskell - Couldn't match expected type

Couldn't match type Integer in Haskell

Couldn't match expected type in Haskell error

Couldn't match expected type of Haskell function

Haskell howManyAboveAverage Couldn't Match Type Error

Couldn't match expected type `IO ()' with actual type `a0 -> m0 a0'

gtk2hs: Couldn't match expected type ‘IO [Int]’ with actual type ‘[Int]’

Converting Haskell to Template Haskell: couldn't match expected type ExpQ

Haskell 'Couldn't match expected type with actual type'

Haskell : Couldn't match expected type ‘a -> a’ with actual type ‘Failable (a -> a)’

Haskell couldn't match expected type float with actual type 'a'

Haskell - Couldn't match expected type ‘b’ with actual type ‘a’