小编Alv*_*ues的帖子

Haskell中的“无法将类型'[]'与'IO'匹配”错误

我正在尝试用Points(我创建的数据类型)列出一个列表,这个想法是在每次迭代中添加一个元素。出了点问题。

我已经尝试过p了,myLoop但它似乎也不起作用。

main = myLoop 
myLoop  = do 
            let p = []
            done <- isEOF
            if done
              then putStrLn ""
              else do inp <- getLine
                      let (label:coord) = words inp
                      p ++  [Point label (map getFloat coord)]
                      -- print (pointerList)
                      myLoop 
Run Code Online (Sandbox Code Playgroud)

我得到这个输出

trabalho.hs:30:23: error:
    • Couldn't match type ‘[]’ with ‘IO’
      Expected type: IO Point
        Actual type: [Point]
    • In a stmt of a 'do' block:
        p ++ [Point label (map getFloat coord)]
      In the expression: …
Run Code Online (Sandbox Code Playgroud)

haskell list type-mismatch do-notation io-monad

-1
推荐指数
1
解决办法
76
查看次数

标签 统计

do-notation ×1

haskell ×1

io-monad ×1

list ×1

type-mismatch ×1