· haskell

Haskell: Reading files


import System.IO

main = do    
    withFile "clustering2.txt" ReadMode (\handle -> do  
        contents <- hGetContents handle   
        putStrLn contents) 

main = do    
    contents <- readFile "clustering2.txt" 
    putStrLn contents 

> :t readFile
readFile :: FilePath -> IO String

> contents <- readFile "clustering2.txt"
> let (bits, nodes) = process contents 
> bits
24
> length nodes
19981
> take 10 nodes
[379,1669,5749,6927,7420,9030,9188,9667,11878,12169]
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket