[Nix-dev] OOP library for Nix.

roconnor at theorem.ca roconnor at theorem.ca
Sat May 10 04:34:56 CEST 2014


I would like to invite you all to 'checkout' my HaskellPackagesFixpoint 
branch.  I have added a little library for "object oriented programming" 
called lib/oop.nix.  Really, it is a library for manipulating open 
recursive functions, but it is couched in object oriented terminology.

The branch contain a little application of the OOP library to 
haskell-packages.  In master, the wreq package is defined as

  wreq = callPackage ../development/libraries/haskell/wreq {
    aeson = self.aeson.override { attoparsec = self.attoparsec_0_11_3_0; };
    attoparsec = self.attoparsec_0_11_3_0;
    lens = self.lens.override {
      aeson = self.aeson.override { attoparsec = self.attoparsec_0_11_3_0; };
    };
  };

However, in my branch it is simply defined as

  wreq = overrideScope ../development/libraries/haskell/wreq (self : {
    attoparsec = self.attoparsec_0_11_3_0;
  });

The overrideScope function is a variant of callPackage where instead of 
overriding the package arguments, the scope is extended.  The 
overrideScope takes advantage of the oop.nix library.

Another, more intricate, example can be found in 
ghc6122Prefs.cabalInstall_1_16_0_2 in haskell-defaults.nix which uses both 
extendScope (which is defined in overrideScope) and override.

I'm planning to play around with this code a little more before asking to 
commit it to mainline.  Please feel free to try it out.  I'm not very good 
at naming things so send any suggestions my way.  I'm particularly unhappy 
with the name "overrideScope" and moderately unhappy with the "nixClass" 
attribute (in oop.nix).

-- 
Russell O'Connor                                      <http://r6.ca/>
``All talk about `theft,''' the general counsel of the American Graphophone
Company wrote, ``is the merest claptrap, for there exists no property in
ideas musical, literary or artistic, except as defined by statute.''


More information about the nix-dev mailing list