Data.Csv @hackage
import Control.Applicative
import Data.Csv
import Data.Text (Text)
import Data.Vector hiding (empty)
import Prelude hiding (length)
data Person = Person {name = !Text, age = !Int} deriving (Show)
instance ToRecord Person where
toRecord (Person name age) = vector [toField name, toField age]
instance FromRecord Person where
parseRecord v
| length v == 2 = Person <$>
v .! 0 <*>
v .! 1
| otherwise = empty
ghci-> let a = Person "John" 18
ghci-> encode [a] -- "john,18\r\n"
ghci-> decode NoHeader "john, 18" :: Either String (Vector Person) -- Right (fromList [Person {name = "john", age = 18}])