缩进错误?

时间:2017-06-11 19:36:06

标签: haskell monads indentation

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

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)) 

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

错误:

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

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

让cities = map stringsToCity s

我是哈斯克尔的乞丐,当我认为我可以学习任何东西时,语言会给我一个新的错误。

1 个答案:

答案 0 :(得分:2)

您无法使用do(或let)结束x <- ...阻止:您必须要对要绑定的变量执行某些操作。< / p>

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

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

当然,您对如何继续main有了更好的了解。例如。你可以print cities,或做更多的计算。