I’ve been stress-testing Claude Opus 5.5 and thought a YAML library with a good API would fill a hole in the ecosystem. The result:
In short, yamlet is a YAML 1.2 library with fast encoding/decoding, preservation of structure (including comments where you want them) and support for generic deriving that compiles to good code for common shapes of data types.
If anyone was doing YAML processing in Haskell and found it lacking, have a look at the API. It was good enough for me to make haskell-gha without any workarounds, but if I missed something, I’d like to know before the first release.
Documentation is mostly Claude-generated, so expect an odd wording here and there, but there’s also plenty of doctests.
9 Likes
What was the motivation for a new yaml library? I assume something about the current libraries isn’t good enough?
You didn’t use pre-existing parser libraries ? wrote the parser from scratch?
Yes, otherwise I would just use an existing one 
- yaml doesn’t support comments at all, HsYAML keeps them only in its event API.
- Both drop the order of keys in a mapping in their high level API. You need to drop down to their event APIs to get it, which are low level and cumbersome to use.
- HsYAML’s parser is very slow (see benchmarks in README). Both pandoc (#6084) and ghcup (#270) switched to it and later back to libyaml because of that.
- yaml goes through aeson’s Value, which leaks its quirks into YAML processing (e.g. infinities become strings +inf/-inf instead of a proper YAML .inf float) and emits JSON-specific paths in error messages without line numbers.
Yes, it’s the same thing aeson does since 2.2. Parser libraries sacrifice either performance or error message quality, I wanted the library to have both. yamlet’s P is essentially a parser monad from flatparse holding YAML specific context with additional position tracking for better error messages.
2 Likes
Is there a way to use encode/decode using autodocodec codecs?
I’m not familiar with autodocodec, but from a quick look it should be fine, just someone would need to provide the autodocodec-yamlet package.
yamlet-1.0.0.0 and yamlet-aeson-1.0.0.0 (a bridge for decoding and encoding YAML with aeson’s instances) are now on Hackage 
3 Likes