Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: Add composeExtensions for composing extension functions #24716

Merged
merged 1 commit into from Apr 11, 2017

Conversation

shlevy
Copy link
Member

@shlevy shlevy commented Apr 7, 2017

No description provided.

@shlevy shlevy requested review from peti and nbp April 7, 2017 18:05
@mention-bot
Copy link

@shlevy, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @peti and @Profpatsch to be potential reviewers.

@shlevy
Copy link
Member Author

shlevy commented Apr 7, 2017

I'm pretty sure this is right and my tests pass, but just wanted a second opinion.

@shlevy
Copy link
Member Author

shlevy commented Apr 7, 2017

Nope, it's wrong, fix incoming

@shlevy
Copy link
Member Author

shlevy commented Apr 7, 2017

OK, should be working now

@shlevy shlevy merged commit 0a15af2 into NixOS:master Apr 11, 2017
@Profpatsch
Copy link
Member

Profpatsch commented Apr 11, 2017

I think something like that should be reviewed before being merged. cc @peti @nbp

It would also be nice to have tests for this function, in lib/tests.nix.

Copy link
Member

@nbp nbp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These modification sounds correct.

I also agree with @Profpatsch that we should be adding tests to our lib functions now (see lib/tests directory).

@shlevy
Copy link
Member Author

shlevy commented Apr 12, 2017

OK, I'll add some tests

@Profpatsch
Copy link
Member

I also agree with @Profpatsch that we should be adding tests to our lib functions now (see lib/tests directory).

For function tests, lib/tests.nix is the correct file. The lib/tests/ folder is only set up for module tests.

@Ericson2314
Copy link
Member

Ericson2314 commented May 26, 2017

Hah I just recently wrote this not knowing it was added. It took me a couple attempts, but then I fixed it by proving the monoid https://gist.github.com/Ericson2314/ab120ccce04ac41b2ec2bec11fda3879 . I'm not sure which of machine-checked tests or hand-written proof is better for inclusion in Nixpkgs, but rest assured this PR is correct 😀 .

@shlevy
Copy link
Member Author

shlevy commented May 26, 2017

@Ericson2314 There are tests already, but if you want to formalize nix in coq and check in a machine-checked proof I'm 💯 👅

@vcunat
Copy link
Member

vcunat commented May 26, 2017

Maybe it would be more practical to compose lists of extensions directly. We already use

let # ...
    toFix = lib.foldl' (lib.flip lib.extends) (self: {}) someListOfExtensions;
in lib.fix toFix

@shlevy
Copy link
Member Author

shlevy commented May 26, 2017

@vcunat More practical in what sense? We've been using this as-is for a while now.

@vcunat
Copy link
Member

vcunat commented May 26, 2017

Just a random thought. It surely depends on particular use case (and the number of extensions you usually combine).

@Ericson2314
Copy link
Member

@vcunat on the contrary I rather do a fold1 with composeExtensions and fix with a fixExtension = f: fix (f {}).

@vcunat
Copy link
Member

vcunat commented May 28, 2017

Yes, using folds explicitly would be a more idiomatic way, at least if we had a forldr1 or foldl1, but it's easy enough to write those.

@Ericson2314
Copy link
Member

Ericson2314 commented May 28, 2017

Well, while it's extra needless work, the monoid identity can always provide the base case for a normal fold too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants