我希望此功能打印给定的IO String
day :: IO String -> IO ()
day p2 = do
putStr "p2: "
putStrLn p2
但是编译器说它需要[Char]
,但是据我所知它基本上与String
相同,所以我的问题是我如何打印IO String
?] >>
这也是stack run
输出的错误:
• Couldn't match type ‘IO String’ with ‘[Char]’ Expected type: String Actual type: IO String • In the first argument of ‘putStrLn’, namely ‘p2’ In a stmt of a 'do' block: putStrLn p2 In the expression: do putStrLn p2 • Couldn't match type ‘IO String’ with ‘[Char]’ Expected type: String Actual type: IO String • In the first argument of ‘putStrLn’, namely ‘p2’ In a stmt of a 'do' block: putStrLn p2 In the expression: do putStrLn p2 | 17 | putStrLn p2 | ^^
我尝试执行
putStr ("p2: " ++ p2)
并使用
我希望此函数打印给定的IO字符串日:: IO字符串-> IO()日p2 =做putStr“ p2:” putStrLn p2但是编译器说它需要[Char],但据我所知基本上...
编译器的错误消息实际上非常清楚。 putStrLn
的参数必须是String
(或[Char]
,这两种类型是彼此的同义词),但是您的p2
不是String
,而是IO String
。