[Haskell-cafe] Data.List / Map: simple serialization?

Dmitri O.Kondratiev dokondr at gmail.com
Fri Jun 10 13:49:23 CEST 2011

On Thu, Jun 9, 2011 at 11:31 AM, Max Bolingbroke <batterseapower at hotmail.com
> wrote:

> If you want plain text serialization, "writeFile "output.txt" . show"
> and "fmap read (readFile "output.txt")" should suffice...
> Max
This code works:

main = do
     let xss = [[1,2,3],[4,5,6],[7,8],[9]]
     writeFile "output.txt" (show xss)
     line <- readFile "output.txt"
     let xss2 = read line :: [[Int]]
     print xss2

As soon as complete file is returned as a single line, using 'fmap'  does
not make sense here:
     line <- readFile "output.txt"
     let xss2 = fmap read line

 When to use 'fmap'?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110610/b04e8896/attachment.htm>

More information about the Haskell-Cafe mailing list