I’ve been looking at yants, which seems to have a nice syntax for “statically” defining types in Nix. I know in reality it’s all runtimed checked, but I like this for this for two reasons:
- In theory the type checking can fail fast and more clearly with a message (
xexpected butypassed) instead of some message about an attribute missing or something, but also more importantly. - I’ve been trying to document my code
NixDocstyle but it’s a bit adhoc and it does get out of sync with changes. But given thatyantsdefines it’s functions using__functor, it seems to associate the type metadata with the function, so I’m pretty sure given an attribute set of functions defined in this manner, I could generate documentation.
I really quite like the yants syntax, and it seems to interact with the existing Nix ecosystem quite well.
But there’s a couple of things I’ve noticed:
yantshasn’t been updated in about 3 years.- It doesn’t seem to have general support for sum types (it has specific support for
either, but not general sums).
But latter I can presumably patch in, and the former isn’t necessarily an issue.
But the fact that it hasn’t been updated leads me to the question, are there other libraries that do something similar to what yants does, that perhaps people are using today? I understand there are the lib.types.* things, but these seem specific to module options, not to just general values in Nix code.
The other library I’ve found is nix-adt, which hasn’t been updated for even longer, nine years, but interestingly has the concept of polymorphic types. That being said, it seems to me that yants is more fleshed out.
Are there other libraries in this space that I’ve missed, particularly being developed now? Ideally, I’d like something like yants but with generic sums and ideally polymorphism, although that may be going down a rabbit hole where one is implementing Hindley–Milner type inference in Nix.
I understand there are alternate languages out there like Nickel but I’d rather not go down that path. A library which can happy work with “untyped” parts of the Nix ecosystem is preferred. There’s plenty of perfectly good existing Nix functionality I want to use, I’d just like to be able to more strictly type and document some of the generic functionality and glue code I’m developing.
In summary, I’d just like any info on any other work in this space that I may have missed, because I don’t want to reinvent the wheel.