Starting with a small test file.
-- cabal: build-depends: dataframe, text, directory
-- cabal: default-extensions: OverloadedStrings, TypeApplications, TemplateHaskell
-- cabal: default-extensions: DataKinds, TypeFamilies, TypeOperators, FlexibleInstances
-- cabal: default-extensions: FlexibleContexts, ScopedTypeVariables, UndecidableInstances
import qualified DataFrame as D
import qualified DataFrame.Lazy as L
import DataFrame.Operators
import Data.Text (Text)
import System.Directory (removeFile)
writeFile "./customers.csv" $ unlines
[ "id,name,surname,dob"
, "1,Ada,Lovelace,1815-12-10"
, "2,Alan,Turing,1912-06-23"
, "3,Grace,Hopper,1906-12-09"
]deriveSchemaValues builds the Schema value from the record;
deriveSchemaFromType adds the HasSchema instance toRecords needs.
data Customer = Customer
{ customerId :: Int
, customerName :: Text
}
deriving (Show, Eq)$(D.deriveSchemaValues ''Customer)
$(D.deriveSchemaFromType ''Customer)
customerSchemaWe can now pass this to the typed CSV reader.
import qualified DataFrame.Typed as DT
import qualified DataFrame.Typed.IO.CSV as TCSV
typed <- TCSV.readCsv @(D.Schema Customer) "./customers_snake.csv"
D.columnNames (DT.thaw typed)