-
Notifications
You must be signed in to change notification settings - Fork 8
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
create purescript-nix-buitins
library
#40
Comments
great idea. Regarding the separated "types" package: would it maybe make sense to split this up into sub packages, in the purescript style of having one repo around one core data type. on the JS PS side there are the For purenix I think the following would make sense
the linked repos contain stub implementations that I needed in a feature branch of miraculix. They follow the idea to be as close as possible to the JS versions, except the 'path' one naturally. What do you think about it? I think it does not contradict with the plan to have |
That's a good idea. I agree that it does make sense to have With those libraries available, I agree it might not make sense to have Another comment: In This is in contrast to PureScript's https://pursuit.purescript.org/packages/purescript-foreign-object/3.0.0/docs/Foreign.Object In practice, If someone wants to get started working on this, please let me know and I can create you some repos under the PureNix Organization to get started with. |
yeah. I'd be up for starting with this. Think I'd like to start with |
I went ahead and created https://github.com/purenix-org/purescript-foreign, you should have an admin invite |
Now I adjusted the bits that I already had to a version that I think is ready to be used. It's my first purenix port. So I'll list a couple of concepts that you'll find in the repo:
If you have any feedback about those workflows, feel free to leave a comment! |
@thought2 I bumped you up from an outside contributor to an owner of the PureNix organization. It looks like you'll have to either check your email or go to https://github.com/purenix-org to accept the invitation. We put together a document for joining the PureNix organization. Please take a look: https://github.com/purenix-org/purenix/blob/main/.github/MEMBERS.md.
Is this mainly for being able to run the tests? I'm guessing we'd hopefully be able to go back to just a single
The tests are really nice! This is exactly the kind of thing I was imagining!
Thanks for documenting this, and keeping the unported code in the codebase (just commented out). At some point I'd like to port |
@cdepillabout great, thanks for the invite. I read the MEMBERS guide and agree to it. Invite is already accepted. Regarding the So the idea was to have a
In the end, it's not so crucial, because the real source of truth of a package's dependencies lives inside the the package set, so those dhall files in the repo are just for the user. And thus, an alternative approach would be to have one single let libDeps = [ "prelude" ] -- potentially more...
let testDeps = ["miraculix-lite"] -- potentially more...
in
{ name = "purescript-foreign"
, dependencies = libDeps # testDeps
, backend = "purenix"
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
}
If you go with just one conventional Thinking about this now, maybe the "let/in" approach is simpler. But I am not sure. |
I also realized this when porting some of the PureNix libraries! It is quite annoying to have the It almost seems weird that there doesn't seem to be a set approach to this in the upstream PureScript packages.
This is basically what I was considering doing (just to have less files in the repo). Want to try to keep to this style for new libraries we port? |
Yes, It think it's simpler with one file. And no real practical benefit we'd get if we go with 3 files. See, the above PR. |
It would be nice to have a library like
purescript-nix-builtins
that provides FFI for all the different Nix builtins (likebuiltins.deepSeq
,builtins.getEnv
,builtins.mapAttrs
, etc). This library should also provide FFI data types for types from Nix that are not available from PureScript by default. For instance, aPath
type to represent Nix paths.A couple other points:
I have a small start of what this library would look like in
cabal2nixWithoutIFD
: https://github.com/cdepillabout/cabal2nixWithoutIFD/blob/484515bdec2ccf9dfc02b9a442b801bc2d17b9cc/purescript-parser-combinator/src/NixBuiltins.pursI think @thought2 may also have some parts of a Nix builtins library in https://github.com/thought2/purescript-miraculix or one of the dependencies.
It might make sense to split this into two packages, one that provides the FFI data types (called something like
purescript-nix-types
), and one that provides the Nix builtins (calledpurescript-nix-builtins
as above). It should be possible to usepurescript-nix-types
without relying onpurescript-nix-buitlins
. This could be used by people who want to write all their own FFI. The mainpurescript-nix-builtins
module should probably re-export everything frompurescript-nix-types
, so most end users never have to directly interact withpurescript-nix-types
.It might make sense to have a
Nix.Builtins
module, and aNix.Builtins.Unsafe
module.Nix.Builtins
would provide mostly type-safe functions, whileNix.Builtins.Unsafe
would provide mostly unsafe, fully-polymorphic functions.For instance,
builtins.toString
is able to take any argument type except a function or a record. It would be tough to give this a completely safe type in PureScript, but theNix.Builtins.Unsafe
module could give this a type liketoString :: forall a. a -> String
. The person using this function would have to take responsibility to never pass it a function or a record.On the other hand, a function like
buitins.length
can be safely typed in PureScript:length :: forall a. List a -> Int
. This type can always be used safely by end users.One function / data type that will be necessary (but is not completely straight-forward) is to represent a Nix function that pattern matches on a record. So something like the Nix function
{ hello ? true, bar }: 123
. I took a stab at creating this here (FunctionWithArgs
andmkFunctionWithArgs
):https://github.com/cdepillabout/cabal2nixWithoutIFD/blob/484515bdec2ccf9dfc02b9a442b801bc2d17b9cc/purescript-cabal-parser/src/Main.purs#L208-L227
The FFI part:
https://github.com/cdepillabout/cabal2nixWithoutIFD/blob/484515bdec2ccf9dfc02b9a442b801bc2d17b9cc/purescript-cabal-parser/src/Main.nix#L9-L13
The text was updated successfully, but these errors were encountered: