dealing with IO vs pure code in haskell
Posted
by Drakosha
on Stack Overflow
See other posts from Stack Overflow
or by Drakosha
Published on 2010-05-29T07:50:19Z
Indexed on
2010/05/29
7:52 UTC
Read the original article
Hit count: 162
haskell
I'm writing a shell script (my 1st non-example in haskell) which is supposed to list a directory, get every file size, do some string manipulation (pure code) and then rename some files. I'm not sure what i'm doing wrong, so 2 questions:
- How should i arrange the code in such program?
I have a specific issue, i get the following error, what am i doing wrong?
error: Couldn't match expected type
[FilePath]' against inferred type
IO [FilePath]' In the second argument ofmapM', namely
fileNames' In a stmt of a 'do' expression: files <- (mapM getFileNameAndSize fileNames) In the expression: do { fileNames <- getDirectoryContents; files <- (mapM getFileNameAndSize fileNames); sortBy cmpFilesBySize files }
code:
getFileNameAndSize fname = do (fname, (withFile fname ReadMode hFileSize))
getFilesWithSizes = do
fileNames <- getDirectoryContents
files <- (mapM getFileNameAndSize fileNames)
sortBy cmpFilesBySize files
© Stack Overflow or respective owner