purenix-org / purenix

Nix backend for PureScript. Transpile PureScript code to Nix.
https://hackage.haskell.org/package/purenix
BSD 3-Clause "New" or "Revised" License
294 stars 8 forks source link

How can I use a Map or Dict or similar thing ? #65

Open luochen1990 opened 4 weeks ago

cdepillabout commented 1 week ago

PureScript has built-in extensible records, which might work for you depending on what you're trying to do: https://github.com/purescript/documentation/blob/master/language/Records.md. PureNix compiles PureScript's built-in records to Nix attrsets.

PureScript also has a foreign-object library, which effectively just wraps around JS objects in the JS backend. This library is not yet ported to PureNix, but you can imagine it would be straightforward(?) to port. (There is also a library called just foreign that is somewhat related depending on what you're trying to do.)

In cabal2nixWithoutIFD, I implemented my own AttrSet type:

https://github.com/cdepillabout/cabal2nixWithoutIFD/blob/484515bdec2ccf9dfc02b9a442b801bc2d17b9cc/purescript-parser-combinator/src/NixBuiltins.purs#L6-L8

This type of thing would ideally go into some sort of nix-builtins library instead.

There is also ordered-collections, which I believe is more similar to Haskell's Map type, and may be what you're looking for. This library also hasn't been ported to PureNix.