繁体   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

这是我正在处理的项目代码的一部分。 这是一个 function 接收玩家的指令并将玩家重定向到另一个 function。 mapList是一个字符串列表,它应该包含 map 的逐步变化。 count是计算玩家输入指令数量的变量。 我遇到的问题是编译器在说这行

inp <- getLine

有错误。 带有主题中所述的消息。 我不知道如何解决这个问题。 请随时查看此链接: Haskell IO:如果您想了解有关此项目的更多信息,请阅读整个文本文件 谢谢你。

您需要在签名中将 function 声明为IO

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

暂无
暂无

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

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