Skip to content

Instantly share code, notes, and snippets.

@takapiko
Created February 8, 2015 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takapiko/ac08422833fa09d92510 to your computer and use it in GitHub Desktop.
Save takapiko/ac08422833fa09d92510 to your computer and use it in GitHub Desktop.
import Text.Regex
import Data.List
readCSV :: (String,String)->IO [[String]]
readCSV (fileName,delimiter) = do
text <- (readFile fileName)
let column = lines text::[String]
elements = map (splitRegex (mkRegex delimiter)) column
return elements
writeCSV :: (String,String) -> [[String]] ->IO ()
writeCSV (fileName,delimiter) csv = do
let column = map (intercalate (delimiter)) csv
text = unlines column
writeFile fileName text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment