type FilePath = String   
  
-- Achtung: existierende Dateien werden überschrieben!  
writeFile :: FilePath -> String -> IO ()  
  
appendFile :: FilePath -> String -> IO ()  
  
-- Lesen erfolgt verzögert ("lazy I/O"), obwohl I/O Aktion!  
readFile :: FilePath -> IO String   

Beispiel

  • Datei wird eingelesen in String
  • Zeilen, Wörter, Zeichen zählen
  • Ausgabe als IO ()
wc :: String -> IO ()   
wc file =   
	do cont <- readFile file   
		putStrLn $ file ++ ": " ++   
			show (length (lines cont),   
			      length (words cont),   
			      length cont)