chpatrick / codec Goto Github PK
View Code? Open in Web Editor NEWEasy bidirectional serialization in Haskell
License: BSD 3-Clause "New" or "Revised" License
Easy bidirectional serialization in Haskell
License: BSD 3-Clause "New" or "Revised" License
Citing from http://hydra.cryp.to/build/916656/log/raw:
Building codec-0.1...
Preprocessing library codec-0.1...
Data/Codec.hs:9:8:
Could not find module ‘Data.Codec.Field’
Use -v to see a list of the files searched for.
Data/Codec.hs:10:8:
Could not find module ‘Data.Codec.Codec’
Use -v to see a list of the files searched for.
Data/Codec.hs:11:8:
Could not find module ‘Data.Codec.TH’
Use -v to see a list of the files searched for.
Data/Codec.hs:12:8:
Could not find module ‘Data.Codec.Tuple’
Use -v to see a list of the files searched for.
The README reads:
You can serialize in any order you like, regardless of field order in the data type
But, sadly, that is no longer true with the Applicative+Profunctor
approach.
(Sorry!)
It seems like it would be possible to move more of this to the type level using TypeLits Symbol
I would like to use codec (a very nice package), but have already made the transition to GHC 8 which this library is currently not compatible with.
The fix is to add a wildcard between vs
and cs
at L81 of Data.Codec.TH
.
Interestingly, the latest template-haskell version is compatible with base-4.7 up to 4.9; unfortunately that only goes as far as GHC 7.8, whereas you currently support GHC 7.6 too.
The simplest way to remain compatible seems to be to use CPP.
Trying to type
:t (,)
$>> f_1 >-< pure ()
>>> f_2 >-< pure 'a' :: (Applicative fr, Applicative fw) => Codec fr fw ((), Char)
results in some "could not deduce" errors
Could not deduce (Buildable ((), Char) y0)
Could not deduce (Field1 ((), Char) () (a0 -> b0 -> (a0, b0)) b1)
Could not deduce (Field2 ((), Char) Char b1 y0)
While an instance Field1 (a, b) a (a -> c -> (a, b)) (X -> c -> (a, b))
exists, it cannot be selected here because the compiler cannot first deduce that ((), Char)
should be equal to (a0, b0)
(fundeps would then take care of the rest).
Annotating (,) :: () -> Char -> ((), Char)
makes the above typecheck, though this causes f_1
and f_2
to be rather annoying to use.
Making them regular functions would be a better fix IMO. Is there a reason why they are defined in typeclasses that I am missing?
I have figured out how to parse an ADT but am not sure how to serialize it well. Instead of the constructor being the initial function, a function that picks the constructor would be the starting function. However, I am not sure how to continue from there.
Using JSON:
data StringEncoded
= Date Year Month Day
| Money Currency Int
stringEncodedObjCodec :: JSONCodec StringEncoded
stringEncodedObjCodec = ???
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.