My function gets a string of type IO [String] by simple manipulations, and I need a String. For example, display.
How to perform type conversion?
|
1 answer
An example is a program that concatenates its arguments:
import System.Environment main = do args <- getArgs putStrLn $ concat args Type getArgs :: IO [String] .
Write the function f :
f :: Monad m => m [[a]] -> m [a] fm = m >>= (\ xs -> return $ concat xs) Let's expand the do notation in the original example:
main :: IO () main = (f getArgs) >>= putStrLn |
IO [String]is not a string, but a list of strings in the IO monad. - andrybak