I am trying to read and print the output from the "readProcess" command mapped onto a list of filenames:
files <- readProcess "ls" [] []
let mdList = map ( \file -> do
md <- readProcess "mdls" [file] []
return md ) $ splitOn "\n" files in
map (\md -> putStrLn md) mdList
putStrLn "Complete"
Each time I try to map putStrLn onto the mdList, I get this error:
Couldn't match type ‘IO String’ with ‘[Char]’
I have read many StackOverflow answers that seem to just use putStrLn on an IO String but I am unable to do so. Also, I am new to Haskell so any other tips are also appreciated.
IO Stringvalue is not a string. It doesn't make sense to want to put anIO String, for the same reason you wouldn't want to eat a cookbook.IO String? Machine code? Assembly instructions? What?doblock. But if you shove adoblock in a function argument, it'll always be a monadic action, not a pure value such as the function might accept.map putStrLnis[String] -> [IO ()], but every statement in yourdoblock must have typeIO Xfor someX(and clearly[IO ()]can't matchIO Xfor anyX). However,mapM_ putStrLn :: [String] -> IO ().