相关疑难解决方法(0)

Haskell - "'do'结构中的最后一个语句必须是一个表达式"

就像它在标题中所说:什么The last statement in a 'do' construct must be an expression意思?我结束了我的do块,putStrLn就像我在几个例子中看到的那样,我得到了一个错误.

码:

main = do args <- getArgs
           file <-readFile "TWL06.txt"
           putStrLn results
Run Code Online (Sandbox Code Playgroud)

io syntax monads haskell

15
推荐指数
3
解决办法
2万
查看次数

Haskell:'do'结构中的最后一个语句必须是一个表达式

嘿,很抱歉在这里转发错误信息,但我已经尝试了所有我能找到的东西,似乎没什么关系.此代码生成错误:

import System.Environment   
import System.Directory  
import System.IO  
import Data.List  

data Node = PathNode String Float Float [String] | NoNode deriving (Show)


main = do
    (filename:args) <- getArgs  
    load filename


load :: String -> IO ()  
load fileName = do
    contents <- readFile fileName  
    let pathStrings = lines contents
        first = head pathStrings
        args = lines first
        path = createNode args
        putStr path


createNode [String] -> Node
createNode (name:x:y:paths) = PathNode name x y paths
createNode [] = NoNode
Run Code Online (Sandbox Code Playgroud)

我知道它与对齐有关,但我已正确对齐'load'函数中的所有调用.我究竟做错了什么?

谢谢

io syntax monads haskell

3
推荐指数
1
解决办法
1463
查看次数

标签 统计

haskell ×2

io ×2

monads ×2

syntax ×2