purenix icon indicating copy to clipboard operation
purenix copied to clipboard

core library support

Open cdepillabout opened this issue 2 years ago • 3 comments

This issue is to track which core libraries have been ported to PureNix.

Done

These are libraries that have already been ported.

Todo

These are libraries that still need to be ported.

  • [ ] catenable-lists
  • [ ] datetime (This might be difficult? I don't think Nix has any built-in support for working with dates or times.)
  • [ ] enums
  • [ ] filterable
  • [ ] foreign (Started by @thought2 in https://github.com/purenix-org/purescript-foreign. Some functions from this library haven't been ported yet, and it is waiting on the lists and transformers packages being ported. See https://github.com/purenix-org/purenix/issues/40#issuecomment-1019074353 for a little more info.)
  • [ ] foreign-object
  • [ ] free
  • [ ] functions
  • [ ] graphs
  • [ ] integers
  • [ ] lazy (This isn't technically necessary, because PureNix is lazy. But it may be nice to have for library compatibility. Also, we probably want something like Haskell's deepseq instead, since Nix does have a builtins.seq function.)
  • [ ] lcg
  • [ ] lists
  • [ ] math
  • [ ] numbers
  • [ ] ordered-collections
  • [ ] psci-support (I'm not sure what PureNix needs to do to get PSCi working. This library may or may not be needed.)
  • [ ] record
  • [ ] semirings
  • [ ] strings (This would be hard to port as-is, since Nix doesn't have any built-in support for UTF8 or Unicode. However, @-sternenseemann has written a proof-of-concept UTF8 library for Nix that we could likely draw inspiration from.)
  • [ ] transformers
  • [ ] typelevel-prelude
  • [ ] validation

Won't Do / Can't Do

These are libraries that either can't be ported to PureNix, or don't make sense to port to PureNix.

  • assert

    Nix does have an assert statement, but I'm not sure it would be able to be used with a similar API to purescript-assert. Creating a purescript-nix-assert library would likely be better.

  • console

    Nix doesn't have any way of writing arbitrary text to the console. There is the builtins.trace Nix function, but that could be wrapped up in it's own library.

  • docs-search

    I'm not sure what this is or how it would be related to PureNix.

  • effect

    Nix doesn't have any way of doing arbitrary effects. In theory, we could have an Effect type for compatibility, but in practice we wouldn't be able to do anything interesting with it.

    edit: There was a little discussion in https://github.com/purenix-org/temp-package-set/pull/1 as to whether or not purescript-effect would make sense for PureNix. There are a couple good points in favor of having purescript-effect.

  • exceptions

    Nix doesn't really have exceptions the same way JavaScript does. Nix does have the builtins.abort, assert, and builtins.tryEval functions, which may be able to be wrapped up in a nice library.

  • gen

    See the problem with random.

  • minibench

    I don't think Nix has any way of getting the current time (or at least to any precision that would be necessary for benchmarking).

  • parallel

    Nix doesn't have any built-in way of running computations in parallel. It is possible we could support this same API in PureNix for compatibility, but it is likely we would only be able to run the computations sequentially.

  • quickcheck

    See the problem with random.

  • random

    As far as I know, Nix doesn't have any sort of random number generator. There is no way to generate random numbers.

    edit: Thinking about this a little more, we could have purescript-random be a pseudorandom number generator (PRNG). All the random functions could just take a seed that has to be passed in. The seed would be the initial seed for the PRNG. This could be useful for people that are willing to pass in a random seed when calling nix-build. This seems like a reasonable way to use libraries like purescript-random, purescript-gen, and purescript-quickcheck.

  • refs

    Nix doesn't have any way of mutating values, so refs are not possible.

  • tailrec

    Nix is lazy, so this sort of trampolining isn't necessary.

cdepillabout avatar Dec 09 '21 01:12 cdepillabout

A couple comments:

  • If you'd like to help with this, please leave a message and we can get you setup with a repo for doing the porting.

  • In my experience, the most time-consuming part of this is writing the FFI. For instance, purescript-arrays has a lot of FFI, and that took a long time to port. But packages like purescript-newtype have no FFI, and that basically takes no time to port.

  • It is quite common for libraries to have dependencies on things like purescript-effect (for MonadEffect), or purescript-tailrec (for MonadRec). These type of dependencies and instances can mostly be ignored and deleted from the ported-code, since they aren't used in PureNix.

  • Once you're ported a library, make sure to add it to the temporary package set. (Or possibly whatever we decide to do with #36.)

  • I wrote a script for automating some of the manual work when porting a PureScript package (basically cloning the repo, creating a new repo in purenix-org, updating the package set, etc): https://github.com/cdepillabout/port-purescript-package. It is unlikely someone else would be able to use this as-is, but it might help get an idea of what needs to be done.

cdepillabout avatar Dec 09 '21 01:12 cdepillabout

I'm interested in giving one of these a shot, whichever you think is in the intersection of most useful and straight-forward. Any suggestions ?

martyall avatar Aug 05 '22 18:08 martyall

@martyall We recently released a newer version of purenix that is based on PureScript-0.15 (instead of 0.14): https://github.com/purenix-org/purenix/pull/51 and https://github.com/purenix-org/purenix/pull/53.

However, we never went back and updated all the actual PureNix PureScript libraries to be based on the versions that are used for the actual PureScript-0.15 package set. All of our current PureNix libraries are based on PureScript libraries that are used with PureScript-0.14. I'm actually pretty surprised that the Quick Start instructions still work even when you use a 0.15 version of PureNix with the current set of libraries based on PureScript-0.14.

So the most helpful thing would probably be to go through all the PureScript libraries that have already been ported to PureNix, and update their versions to the same versions used in the actual PureScript-0.15 package set. Although that would likely be quite annoying to do unless you automated or semi-automated the process!


Other than that, the most helpful thing might be to try to work on some sort of nix-builtins library as described in https://github.com/purenix-org/purenix/issues/40.

Or, if you're coming from Haskell, one of the most interesting libraries to try to port to PureNix might be purescript-transformers, since that contains all the monad transformers and mtl type-classes. Having them be available in Nix would be neat.

cdepillabout avatar Aug 06 '22 05:08 cdepillabout