Here's a function that gets the length of a file given the filename:
numLines :: Filename -> IO Int numLines name = do contents <- readFile name return (length (lines contents))
And a main function to call that function:
main = do len <- numLines "Files.hs" putStr $ show len
But what if we want to call numLines from another
function, say we want to give it a list of filenames:
numLinesList' :: [Filename] -> [Int]
numLinesList' (firstFile:rest)
= (numLines firstFile):(numLinesList' rest)Hugs will complain:
*** Type : IO Int *** Does not match : Int