You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, abstract lets me take a function that expects an n-ary array as input and gives me n nested lambdas that otherwise behave the same way. On the other end, apply lets me take an n-ary function and apply it to an array.
They seem like they'd both be pretty simple to implement as primops and would eliminate much of the overhead building up or breaking down the accumulator array.
For context, I'm reviving the deterministic evaluation stuff we were doing in #553, but instead trying out @fkz's idea to do as much of as possible in pure Nix and replacing impure primops with scopedImport. As such, I do a few generic operations over the impure primops, and use the functions above to create generic wrapper functions around primops of various arities. I care about performance because I'm injecting this pretty deeply across an entire nixpkgs evaluation and don't want to slow it to a halt.
Even without my use case, these seem like they could allow for easy and cheap generic manipulation of functions in Nix, which I'm sure someone will find good uses for somewhere. If people agree that they could be useful, I'd be happy to make a PR adding them.
Edit: in practice for my deterministic evaluator, I could take advantage of the fact that all primops I care about have 0, 1, or 2 operands, and not try to be overly generic 😄 but still this would be more fun.
Edit 2: I suppose I could write apply more efficiently than what I have above by using an index and not repeatedly tailing the array.
The text was updated successfully, but these errors were encountered:
I'm writing some code right now that looks like this:
Basically,
abstract
lets me take a function that expects an n-ary array as input and gives me n nested lambdas that otherwise behave the same way. On the other end,apply
lets me take an n-ary function and apply it to an array.They seem like they'd both be pretty simple to implement as primops and would eliminate much of the overhead building up or breaking down the accumulator array.
For context, I'm reviving the deterministic evaluation stuff we were doing in #553, but instead trying out @fkz's idea to do as much of as possible in pure Nix and replacing impure primops with
scopedImport
. As such, I do a few generic operations over the impure primops, and use the functions above to create generic wrapper functions around primops of various arities. I care about performance because I'm injecting this pretty deeply across an entire nixpkgs evaluation and don't want to slow it to a halt.Even without my use case, these seem like they could allow for easy and cheap generic manipulation of functions in Nix, which I'm sure someone will find good uses for somewhere. If people agree that they could be useful, I'd be happy to make a PR adding them.
cc @edolstra @shlevy @domenkozar
Edit: in practice for my deterministic evaluator, I could take advantage of the fact that all primops I care about have 0, 1, or 2 operands, and not try to be overly generic 😄 but still this would be more fun.
Edit 2: I suppose I could write
apply
more efficiently than what I have above by using an index and not repeatedlytail
ing the array.The text was updated successfully, but these errors were encountered: