Stream: cull-os

Topic: Typed Lambda Arguments


view this post on Zulip RGBCube (Jul 13 2024 at 08:58):

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.

view this post on Zulip RGBCube (Jul 13 2024 at 09:02):

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


Last updated: Oct 12 2024 at 21:45 UTC