[Haskell-beginners] (Basic?) IO question

Guillaume Basse gw.basse at gmail.com
Wed Jan 18 19:35:34 CET 2012


Hello,

So I've been trying to print some information in a file. I have two
versions of the same function: one of them doesn't work and I don't
understand why.
Here are the functions:

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

-- This one works as intended when called from ghci
renderTrackInfosToFile :: FilePath -> String -> IO [TrackInfos] -> IO ()
renderTrackInfosToFile filename sep ls = do nls <- ls
                                                                writeFile
filename (intercalate "\n" $ map (renderTrackInfo sep) nls)
                                                                return ()

-- This one does nothing when called from ghci
renderTrackInfosToFile2 :: FilePath -> String -> [TrackInfos] -> IO ()
renderTrackInfosToFile2 filename sep ls = writeFile filename (intercalate
"\n" $ map (renderTrackInfo sep) ls)


renderTrackInfo :: String -> TrackInfos -> String

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Both functions load in ghci, and the following commands are issued:

> -- c :: IO [TrackInfos]
> liftM (renderTrackInfosToFile2 "blabla.txt" "|")  c -- this command seems
to do absolutely nothing
> renderTrackInfosToFile "blabla.txt" "|"  c -- this one works as intended

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

And this is not the first time I have this sort of problem using liftM. I
now that I'm missing something important here,
can anyone explain me my mistake?

Much thanks,

Guillaume Basse
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120118/c7ff4d17/attachment.htm>


More information about the Beginners mailing list