[英]Haskell: Couldn't match expected type ‘IO t0’ with actual type ‘[Char]’
myTakeWhile :: (a-> Bool ) -> [a] -> [a]
myTakeWhile _ [] = []
myTakeWhile pred (head:tail) = if pred head
then head:myTakeWhile pred tail
else []
main = myTakeWhile (/= ' ') "This is practice."
gives me this error:给我这个错误:
Couldn't match expected type ‘IO t0’ with actual type ‘[Char]’
• In the expression: main
When checking the type of the IO action ‘main’
A main
always has type IO something
, not a String
which is the result type myTakeWhile (/= ' ') "This is practice."
main
始终具有类型IO something
,而不是结果类型为myTakeWhile (/= ' ') "This is practice."
的String
。 . .
You can work with print:: Show a => a -> IO ()
to print it as a string literal , or putStrLn:: String -> IO ()
to print the content of the string, so:您可以使用print:: Show a => a -> IO ()
将其打印为字符串文字,或putStrLn:: String -> IO ()
打印字符串的内容,因此:
main :: IO ()
main = print (myTakeWhile (/= ' ') "This is practice.")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.