Comments (6)
from cassava.
How these instances would work? ToField
/ FromField
instances are "leaf"s: parsing a cell value into haskell value. What Generics
would do there? I can think of deriving for newtypes, but these can be derived using newtype
strategy anyway.
from cassava.
There can't exist reasonable encoding for all cases, e.g. for product types. But it exists for subset of sum types with constructors of 0- or 1-arity:
data Foo = Foo
data Foo = Bar | Baz Int
It's similar to UntaggedValue
encoding from aeson. IIRC it should be possible to provide instances only for those cases without any dirty hacks.
from cassava.
Enum case makes sense. 1-arity is suspicious.
I'd suggest defining newtypes to be used with deriving via so the user tells what they want (instead of using clever generics trying to guess). That has an additional benefit that deriving mechanisms stay independent.
FWIW, I plan to make that change to aeson
(in year or so, I'm not keen to break people too often).
from cassava.
Enum case makes sense. 1-arity is suspicious.
I'd suggest defining newtypes to be used with deriving via so the user tells what they want (instead of using clever generics trying to guess). That has an additional benefit that deriving mechanisms stay independent.
FWIW, I plan to make that change to
aeson
(in year or so, I'm not keen to break people too often).
I think we can select precisely which instances to allow (see PR).
It works only for 'single nullary' or 'sum with 0,1 constructors' types and doesn't allow deriving for newtypes.
Actually, another option could be not adding default method at all, so user would have to write instance explicitly in case of such need.
from cassava.
FWIW, I plan to make that change to aeson (in year or so, I'm not keen to break people too often).
Yeah, I like the idea. Current behavior is slightly confusing
from cassava.
Related Issues (20)
- Reading NaNs HOT 1
- Please bump `base` to allow `4.14` HOT 1
- cassava doesn't compile with ghc 9.0.1rc1 even with --allow-new HOT 3
- Loosen bounds on latest base HOT 2
- better control of generic field name parsing
- Doesn't work with bytestring-0.10.12.0 HOT 1
- Not clear what is meant by unpacking HOT 1
- base version mismatch in 0.5.2.0 HOT 2
- Can ToField have Vectors/Functors instances?
- Isn't csv a text-based rather than binary(bytestring)-based format? HOT 2
- Example code missing salaries.csv file
- Per-line parser reporting per-line errors HOT 3
- parseField does not range-check for Word16
- Allow building with `vector-0.13.*` HOT 1
- encodeRecord variant that does not append recordSep
- Call for maintainer(s) HOT 2
- FromNamedRecord and number of rows with values less than rows in file
- GHC 9.10
- Accumulating error messages for failed fields when decoding named records 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 cassava.