-
-
Notifications
You must be signed in to change notification settings - Fork 173
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
Discussion: Add language support for alternative imports #163
Comments
This sounds like a really good idea that would fix a bunch of problems at once, nice 👏 Some questions:
As I understand it, we want Unrelated: how about the proposal from #70 of having |
I don't think reusing |
@f-f: Yeah, this would be like I think whether or not to add |
This implements dhall-lang/dhall-lang#172, by adding "alternative imports", as detailed in dhall-lang/dhall-lang#163. We add: - a `?` operator for specifying alternatives for Imports that fail to resolve - a `missing` keyword for impossible imports (identity for the above operator) Also adds tests for all of the above.
I've gotten a couple of requests for supporting mirrors (i.e. alternative ways to retrieve an import) and I wanted to propose a more general solution for addressing this and other issues.
We could add a new
?
operator to separate two arbitrary expressions (not necessarily imports) where:e₀ ? e₁
... means try to resolve expression
e₀
and if that fails then resolve expressione₁
. You would also be able to chain these operators and the parentheses would be optional since this fallback behavior is associative:There would also be a corresponding identity of the
?
operator calledmissing
that is an import that always fails to resolve:One motivation for providing
?
is to improve resilience, such as in #162 where @f-f mentioned using GitLab as a mirror for the Prelude in case GitHub goes down. Using this?
operator users wouldn't need to modify their code whenever GitHub goes down if they specify their import like this:This would also solve another feature request in #70 where a person could provide an environment variable fallback if a URL was not available:
... where
SERVICE_FALLBACK
might contain a Dhall expression or a new URL to importYou could also use the same operator to fall back to a pure expression. For example, if you wanted to gracefully fall back if an environment variable is missing, you could make the environment variable
Optional
, like this:The text was updated successfully, but these errors were encountered: