I was thinking about this yesterday. Even though a lot of the stdlib will be in Rust, which eagerly checks for types, we need a way to do it in userspace too.
So I decided on this:
{
filter = x :: lambda any boolean: y :: list (typeOf x).input: <impl here>
}
This would sugar down into something that's equivalent to this but with better error messages:
{
filter = x: assert (typeOf x) == lambda any boolean ==> y: assert (typeOf y) == (typeOf x).input ==> <impl here>;
}
How this works is you can specify expressions between the ::
and :
, and they get compared to the type of the argument every time the lambda is called.
==>
is normally for importing namespaces, but it can be used for an equivalent of Nix's builtins.seq
without the parens by making functions return empty attribute sets or maybe even some information in that attribute set when they pass and throw
if they don't, making it bubble up with a trace.
I want to take a shot at implementing this in Nix. It's backwards compatible syntax and shouldn't be that hard to implement, and having a nice demo would be neat
This will now be done with pattern matching and will work everywhere. <pat> :: <expr>
is a valid pattern match: \x :: number: x + 1
Last updated: Nov 21 2024 at 09:45 UTC