Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- recDec :: [Type] -> Type
- mkColSynDec :: TypeQ -> Name -> DecQ
- mkColLensDec :: Name -> Type -> Text -> DecsQ
- lowerHead :: Text -> Maybe Text
- colDec :: Text -> String -> Text -> Either (String -> Q [Dec]) Type -> Q (Type, [Dec])
- declareColumn :: Text -> Name -> DecsQ
- declarePrefixedColumn :: Text -> Text -> Name -> DecsQ
- data RowGen (a :: [Type]) = RowGen {
- columnNames :: [String]
- tablePrefix :: String
- separator :: Separator
- rowTypeName :: String
- columnUniverse :: Proxy a
- inferencePrefix :: Int
- lineReader :: Separator -> Producer [Text] (SafeT IO) ()
- rowGen :: FilePath -> RowGen CommonColumns
- rowGenCat :: FilePath -> RowGen CommonColumnsCat
- tableTypes :: String -> FilePath -> DecsQ
- prefixSize :: Int
- colNamesP :: Monad m => Producer [Text] m () -> m [Text]
- tableTypesText' :: forall a c. (c ~ CoRec ColInfo a, ColumnTypeable c, Monoid c) => RowGen a -> DecsQ
- tableTypes' :: forall a c. (c ~ CoRec ColInfo a, ColumnTypeable c, Monoid c) => RowGen a -> DecsQ
Documentation
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.
declareColumn :: Text -> Name -> DecsQ Source #
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
.
declarePrefixedColumn :: Text -> Text -> Name -> DecsQ Source #
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.
RowGen | |
|
rowGenCat :: FilePath -> RowGen CommonColumnsCat Source #
Like rowGen
, but will also generate custom data types for
Categorical
variables with up to 8 distinct variants.
tableTypes :: String -> FilePath -> DecsQ Source #
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
prefixSize :: Int Source #
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
.