Haskell: 使用点运算符组合两个函数时出错
Haskell: error by using point-operator to combine two functions
我刚开始 Haskell 和 运行 遇到 (.) 的问题。
let myPrint = putStrLn . show
myPrint ("Hello World!")
<interactive>:171:10:
Couldn't match expected type `()' with actual type `[Char]'
In the first argument of `myPrint', namely `("hello Wordl!")'
In the expression: myPrint ("hello Wordl!")
In an equation for `it': it = myPrint ("hello Wordl!")
关于我定义的函数打印的信息:
Prelude> :info myPrint
myPrint :: () -> IO ()
输出不应该是:
myPrint:: Show a => a -> IO ()
您正在使用旧的 GHCi/Hugs 解释器,其中应用了可怕的单态限制。我建议你更新它。
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
Prelude> let myPrint = putStrLn . show
Prelude> :t myPrint
myPrint :: Show a => a -> IO ()
我刚开始 Haskell 和 运行 遇到 (.) 的问题。
let myPrint = putStrLn . show
myPrint ("Hello World!")
<interactive>:171:10:
Couldn't match expected type `()' with actual type `[Char]'
In the first argument of `myPrint', namely `("hello Wordl!")'
In the expression: myPrint ("hello Wordl!")
In an equation for `it': it = myPrint ("hello Wordl!")
关于我定义的函数打印的信息:
Prelude> :info myPrint
myPrint :: () -> IO ()
输出不应该是:
myPrint:: Show a => a -> IO ()
您正在使用旧的 GHCi/Hugs 解释器,其中应用了可怕的单态限制。我建议你更新它。
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
Prelude> let myPrint = putStrLn . show
Prelude> :t myPrint
myPrint :: Show a => a -> IO ()