Closed samhh closed 4 years ago
Hi @samhh, can you also tell what output you expect from the codec? It's not clear what's the problem. Also, generally, specifying top-level signatures of all codecs can help with resolving issues, because due to type inference the inferred types of codecs might not be the same you expect.
Hey @chshersh,
In my real codebase I do have explicit type signatures, just tried to write a pared down repro. :slightly_smiling_face:
What's confusing me is that the encoded value cannot be decoded - is this expected behaviour? I'd generally expect decode (encode x) == x
to hold.
@samhh Thanks for more details! From the implementation of the tableMap
codec I can see that it doesn't handle array of tables as an argument codec to tableMap
at the moment. I guess, it should be possible to patch tableMap
and take this into consideration.
Just wonder, what is your real use case and why you want to have such nested configurations? I'm curious about different use-cases for TOML and how it can be used in various scenarios 🙂
My use case is something I've just started working on.
I'm using TOML for user configuration and, until I'm given a compelling reason not to, also for data caching. The structure of said data is currently like this:
data Cache = Cache
{ timestamp :: LocalTime,
feeds :: Map PodcastId (Map EpisodeId Episode)
}
I'm contemplating changing that to this, which prompted this ticket:
data Cache = Cache
{ timestamp :: LocalTime,
feeds :: Map PodcastId [Episode]
}
@samhh we prepared a fix in #337 . Let us know if it doesn't work for your use-case 🙂
Current known limitation of the solution – it doesn't preserve empty lists in values of the map.
That's working perfectly, many thanks!
Me again! :wave:
It's possible I'm misusing the codecs. I've tried and failed to simplify the repro beyond this point, hopefully this helps.
The encoded value looks like this written to a file with
Toml.encodeToFile
: