Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write list to file?

Tags:

list

io

haskell

I am trying:

import System.IO
saveArr = do
    outh <- openFile "test.txt" WriteMode
    hPutStrLn outh [1,2,3]
    hClose outh

but it doesn't works... output:

No instance for (Num Char) arising from the literal `1'

EDIT OK hPrint works with ints but what about float number in array? [1.0, 2.0, 3.0]?

like image 607
MMM Avatar asked Dec 22 '22 02:12

MMM


1 Answers

hPutStrLn can only print strings. Perhaps you want hPrint?

hPrint outh [1,2,3]
like image 125
kennytm Avatar answered Dec 25 '22 22:12

kennytm