-
Notifications
You must be signed in to change notification settings - Fork 81
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
Dynamic import resolution #1865
Comments
Do you really need your file name #1694 (lazy imports), while not necessarily implying dynamic imports, are I believe a first step toward potentital dynamic imports - work is being done on this front in e.g. #1807. |
I think dynamic imports could be useful. The hydra configuration system (to which I am a contributor) has a feature called the defaults list which is basically an import system that allows for some degree of dynamic behavior. |
As a motivating example of how dynamic imports could be useful, I'll give a rough translation into nickel-lang of Hydra's specializing configuration example. Let's say we want to configure a machine learning application that will train a given model on a given dataset. Suppose we have the following tree of files:
Here If dynamic imports were possible in nickel, we could write the following in
Piping the configuration to the ML application then looks like this:
And switching from alexnet to resnet becomes as simple as this, with all imports being automatically adjusted:
I think it's possible to achieve something similar using Nickel's |
@yannham I don't disagree. It is completely possibly to just create a tmp file or a symlink every time. But assuming I have many files to process, that means significant I/O overhead and many files to cleanup afterwards. |
I agree that dynamic imports are useful in general, and can't always be just replaced with a static import and symlinks. I just wanted to make sure you knew about this simplest option first, which could fit the bill in some situations 🙂 Thanks for the example, @Jasha10. As always there's a tradeoff there between static and dynamic: while dynamic is more flexible, it also disallows a whole class of optimizations and static analysis. In general most compiled, structured languages don't allow dynamic imports (think Rust, OCaml, Haskell, Swift, C, C++, etc.). It's a bit different in scripting languages, as I reckon javascript has the The example given here isn't entirely compelling IMHO, as it trades a bit of boilerplate for a more fragile dynamic idiom (for example, it might be harder to get the LSP to work on dynamic import, it's also not clear how this interact with static typing, etc.). But I can see how it could be, on a larger example, or a different example when you might not want to touch the source of the config but still add files or datasets. Dynamic imports aren't out of the question, but they need to be carefully designed - in particular I'm thinking right now that they should be separate from normal imports (if only using a |
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
This feature is closely related to, and builds on #1864.
Consider again the Nickel program
validate.ncl
:To call apply it to some file
data.json
I would executenickel apply validate.ncl --arg json_data $(cat data.json)
. However, if Nickel supported dynamic import resolution thenvaliate.ncl
would become:And I could simply execute
nickel apply validate.ncl --arg json_data_path data.json
Describe the solution you'd like
A clear and concise description of what you want to happen.
I would like
import
to accept any value of typeString
and become a regular function of typeString -> Dyn
(much like in Nix).Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
N/A
Additional context
Add any other context or screenshots about the feature request here.
N/A
The text was updated successfully, but these errors were encountered: