Comments (3)
generate CSV header from the type with generics-sop metadata
from heidi.
After a fair bit of trial and error, header
produces a
simple representation of an arbitrary type which can be pretty-printed
as a tree :
data A = MkA Int deriving (Eq, Show, G.Generic, Heidi)
data B = MkB Int Char deriving (Eq, Show, G.Generic, Heidi)
data B2 = MkB2 { b21 :: Int, b22 :: Char } deriving (Eq, Show, G.Generic, Heidi)
data C = MkC1 {c1 :: Int} | MkC2 A | MkC3 () deriving (Eq, Show, G.Generic, Heidi)
data R = MkR { r1 :: B2, r2 :: C , r3 :: B } deriving (Eq, Show, G.Generic, Heidi)
λ> printBox $ headerBox $ header (Proxy @R)
R
------------------------------------------------
MkR
R
------------*------------*----------------------
r1 | r3 | r2
B2 B C
---------- ---------- ------+------+------
MkB2 MkB MkC3 | MkC1 | MkC2
B2 B () Int A
----*----- ----*----- ---
b21 | b22 _0 | _1 MkA
Int Char Int Char Int
from heidi.
In case someone else wants to move this forward, my thinking so far is as follows:
-
header
computes a rose tree representation of a type, and only requires aGeneric
and an empty instance ofHasHeader
(populated automatically via the Generic instance) (see https://github.com/ocramz/heidi/blob/master/src/Core/Data/Frame/PrettyPrint.hs#L152 ) - similarly,
encode
uses the generic representation of a value and produces a corresponding representation; values however (i.e. data rows) are "flattened" from rose trees into one-level deep tries, keyed by lists of elements (https://github.com/ocramz/heidi/blob/master/src/Data/Generics/Encode/Internal.hs#L101). This flat representation makes lookup and traversal convenient. Aheidi
dataframe is produced byencode
ing all values in a list. - the rose trees produced by
header
are convenient for pretty-printing the sum-of-products structure of general Haskell ADTs, as seen above (implementation at https://github.com/ocramz/heidi/blob/master/src/Core/Data/Frame/PrettyPrint.hs#L91 ) - additionally, the trees produced by
header
contain all possible combination of keys that might appear inencode
d values, which is whyHeader
values can be used in the Show instance of anencode
d dataframe:- take few rows (e.g. 10) for each value, perform lookup using the
Header
keys and render in the corresponding column, under the header
- take few rows (e.g. 10) for each value, perform lookup using the
from heidi.
Related Issues (20)
- Categorical variables
- move `header` into Heidi typeclass HOT 1
- Couple Frame and Header HOT 1
- Improve the explanation around the library rationale
- tidy data operations with lists as keys HOT 1
- add Semigroup/Monoid instance to Row HOT 1
- add Semigroup/Monoid instances to Frame HOT 1
- Multi-key-column joins HOT 2
- Haddocks don't build due to generic-trie HOT 4
- Incorporate generic-trie HOT 1
- Fix usage of Semigroup/Monoid instance of Header
- unincorporate generic-trie and just import the latest version
- Implement spread and gather HOT 1
- add dplyr operations HOT 3
- explain/log outcome of each operation
- Traversal' rather than Decode
- CSV output
- date/ time types
- FUNDING.yml parsing errors HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from heidi.