Haskell:let x = fn(intStr)之间的区别; 返回x并返回fn(inpStr)?

gef*_*fei 1 monads haskell

在Haskell中,我有一个功能

fn :: String -> Int
Run Code Online (Sandbox Code Playgroud)

然后我尝试在IO monad中使用它

mn = do
     inpStr <- readFile "input.txt"
     return fn(inpStr)
Run Code Online (Sandbox Code Playgroud)

编辑:我使用的是GHCi,版本7.10.2

我收到了错误消息

Couldn't match type ‘[Char] -> Integer’ with ‘IO b’
    Expected type: String -> IO b
      Actual type: String -> [Char] -> Integer
    Relevant bindings include mn :: IO b (bound at 01.hs:13:1)
    The function ‘return’ is applied to two arguments,
    but its type ‘([Char] -> Integer) -> String -> [Char] -> Integer’
    has only three
    In a stmt of a 'do' block: return fn (inpStr)
    In the expression:
      do { inpStr <- readFile "input.txt";
           return fn (inpStr) }
Run Code Online (Sandbox Code Playgroud)

但是,如果我将我的代码更改为

mn = do
     inpStr <- readFile "input.txt"
     let x = fn(inpStr)
     return x
Run Code Online (Sandbox Code Playgroud)

有用.

let x = fn(intStr); return x和之间有什么区别return fn(inpStr)

pha*_*dej 8

return fn(inpStr)是一样的return fn insStr.你可能想要的return (fn insStr).

在Haskell中没有函数应用的括号,并置就足够了.括号用于分组事物.