缩进错误?

an indentation error?

我想知道如何在 Haskell 中使用标识,但我在这段代码中遇到问题:

module TestTSPGA where 

import TSPGA -- in this we have the type used on the second function
import Data.List

main :: IO () 
main = do 
          contents <- readFile "aaaa.txt" 
          let s = map words (lines contents) 
          let cities = map stringsToCity s 

stringsToCity :: [String] -> City 
stringsToCity [c, x, y] = (read c, (read x, read y)) 

错误与Whosebug中的n个问题相同,我尝试修复了n次,但没有成功。

错误:

C:\Users\xxx\Desktop\TestTSPGA.hs:11:10: 错误:

'do' 块中的最后一个语句必须是表达式

let cities = map stringsToCity s

我是haskell的初学者,当我认为我可以学到任何东西时,语言显示了一个新的错误。

您不能以 let(或 x <- ...)结束 do 块:您必须对绑定的变量执行某些操作。

最简单的解决方法是什么都不做:

main = do 
   contents <- readFile "aaaa.txt" 
   let s = map words (lines contents) 
   let cities = map stringsToCity s 
   return ()

您肯定对如何继续 main 有更好的想法。例如。你可以print cities,或者做更多的计算。