Frames-0.7.0: Data frames For working with tabular data files

Frames.TH

Description

Code generation of types relevant to Frames use-cases. Generation may be driven by an automated inference process or manual use of the individual helpers.

Synopsis

# Documentation

recDec :: [Type] -> Type Source #

Generate a column type.

Declare a type synonym for a column.

Declare lenses for working with a column.

colDec :: Text -> String -> Text -> Either (String -> Q [Dec]) Type -> Q (Type, [Dec]) Source #

For each column, we declare a type synonym for its type, and a Proxy value of that type.

Splice for manually declaring a column of a given type. For example, declareColumn "x2" ''Double will declare a type synonym type X2 = "x2" :-> Double and a lens x2.

Splice for manually declaring a column of a given type in which the generated type synonym's name has a prefix applied to the column name. For example, declarePrefixedColumn "x2" "my" ''Double will declare a type synonym type MyX2 = "x2" :-> Double and a lens myX2.

# Default CSV Parsing

data RowGen (a :: [Type]) Source #

Control how row and named column types are generated. The type argument is a type-level list of the possible column types.

Constructors

 RowGen FieldscolumnNames :: [String]Use these column names. If empty, expect a header row in the data file to provide column names.tablePrefix :: StringA common prefix to use for every generated declaration.separator :: SeparatorThe string that separates the columns on a row.rowTypeName :: StringThe row type that enumerates all columns.columnUniverse :: Proxy aA record field that mentions the phantom type list of possible column types. Having this field prevents record update syntax from losing track of the type argument.lineReader :: Separator -> Producer [Text] (SafeT IO) ()A producer of rows of ’T.Text’ values that were separated by a Separator value.

A default RowGen. This instructs the type inference engine to get column names from the data file, use the default column separator (a comma), infer column types from the default Columns set of types, and produce a row type with name Row.

Like rowGen, but will also generate custom data types for Categorical variables with up to 8 distinct variants.

Like tableType, but additionally generates a type synonym for each column, and a proxy value of that type. If the CSV file has column names "foo", "bar", and "baz", then this will declare type Foo = "foo" :-> Int, for example, foo = rlens @Foo, and foo' = rlens' @Foo.

# Customized Data Set Parsing

Inspect no more than this many lines when inferring column types.

colNamesP :: Monad m => Producer [Text] m () -> m [Text] Source #

Generate a type for a row of a table. This will be something like Record ["x" :-> a, "y" :-> b, "z" :-> c]. Column type synonyms are not generated (see tableTypes'). tableType' :: forall a. (ColumnTypeable a, Monoid a) => RowGen a -> DecsQ tableType' (RowGen {..}) = pure . TySynD (mkName rowTypeName) [] \$ (runIO (P.runSafeT (readColHeaders opts lineSource)) >>= recDec') where recDec' = recDec . map (second colType) :: [(T.Text, a)] -> Q Type colNames' | null columnNames = Nothing | otherwise = Just (map T.pack columnNames) opts = ParserOptions colNames' separator (RFC4180Quoting '"') lineSource = lineReader separator >-> P.take prefixSize

Tokenize the first line of a ’P.Producer’.

tableTypesText' :: forall a c. (c ~ CoRec ColInfo a, ColumnTypeable c, Monoid c) => RowGen a -> DecsQ Source #

Generate a type for a row of a table all of whose columns remain unparsed Text values.

tableTypes' :: forall a c. (c ~ CoRec ColInfo a, ColumnTypeable c, Monoid c) => RowGen a -> DecsQ Source #

Generate a type for a row of a table. This will be something like Record ["x" :-> a, "y" :-> b, "z" :-> c]. Additionally generates a type synonym for each column, and a proxy value of that type. If the CSV file has column names "foo", "bar", and "baz", then this will declare type Foo = "foo" :-> Int, for example, foo = rlens @Foo, and foo' = rlens' @Foo.