我是 Haskell 的新手,我想知道如何在 Haskell 中打印两个函数的结果,我会在 c++ 中执行以下操作:
cout << f() << g();
或者在 C# 中:
Console.WriteLine(f() + " " + g());
在 Haskell 我尝试了类似的东西
main =
--putStr ( show $ square 3 )
putStr ( show $ fibSeries 12 )
square :: Int -> Int
square x = x * x
fib :: Int -> Int
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
fibSeries :: Int -> [Int]
fibSeries x = map fib [0..x]
但我不得不评论第一个命令,因为它给了我一个编译时错误。
错误是:
src\Main.hs:21:5:
Couldn't match expected type `(String -> IO ()) -> String -> t0'
with actual type `IO ()'
The function `putStr' is applied to three arguments,
but its type `String -> IO ()' has only one
In the expression:
putStr (show $ square 3) putStr (show $ fibSeries 12)
In an equation for `main':
main = putStr (show $ square 3) putStr (show $ fibSeries 12)