我正在嘗試在Haskell中進行一些編程。我試圖讀取一個文件,然後通過使用行函數將文件中的每一行放在一個列表中。下面是部分代碼:readFile後使用線條
file = "muh.rtr"
readTrack :: String -> Track
readTrack file =
do let defFile = readFile file
let fileLines = lines defFile
不過,我不斷收到此錯誤:
Parser.hs:22:39:
Couldn't match expected type `String' with actual type `IO String'
In the first argument of `lines', namely `defFile'
In the expression: lines defFile
In an equation for `fileLines': fileLines = lines defFile
我一直在網上搜索了幾個小時,現在希望的地方找到一些答案,但我沒有那麼幸運了至今。
[這裏有一個答案(HTTP://計算器。com/questions/12664050/works-in-ghci-but-not-when-loaded/12665589#12665589)我給了一個和你一樣得到相同錯誤信息的人。 – AndrewC