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 typeIO something
, not aString
which is the result typemyTakeWhile (/= ' ') "This is practice."
.You can work with
print :: Show a => a -> IO ()
to print it as a string literal, orputStrLn :: String -> IO ()
to print the content of the string, so: