Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

24 lines (18 sloc) 0.66 kB
{-# LANGUAGE ScopedTypeVariables, DeriveGeneric #-}
import qualified Data.ByteString.Lazy as BL
import Data.Csv
import qualified Data.Vector as V
import GHC.Generics
data Person = Person String Int deriving Generic
instance FromRecord Person
instance ToRecord Person
persons :: [Person]
persons = [Person "John" 50000, Person "Jane" 60000]
main :: IO ()
main = do
BL.writeFile "salaries.csv" $ encode (V.fromList persons)
csvData <- BL.readFile "salaries.csv"
case decode csvData of
Left err -> putStrLn err
Right v -> V.forM_ v $ \ (Person name salary) ->
putStrLn $ name ++ " earns " ++ show salary ++ " dollars"
Jump to Line
Something went wrong with that request. Please try again.