简体   繁体   English

Haskell IO:无法将“IO”类型与“[]”匹配

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

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.这是一个 function 接收玩家的指令并将玩家重定向到另一个 function。 mapList is a list of String which supposed to contain the changes of the map step by step. mapList是一个字符串列表,它应该包含 map 的逐步变化。 count is the variable to count the number of instructions the player has input. count是计算玩家输入指令数量的变量。 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.请随时查看此链接: Haskell IO:如果您想了解有关此项目的更多信息,请阅读整个文本文件 Thank you.谢谢你。

You need to declare the function as IO in the signature:您需要在签名中将 function 声明为IO

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM