Comments (3)
Another approach might be to provide a way to convert an import to return an Optional
value then the user can use Optional/fold
to supply a default value if the import is absent.
The other reason that I suggest this is that at some point Dhall might have an operator similar to Haskell's (<|>)
operator specialized to Maybe
that allows chaining optional values as fallbacks. In other words, something like the following pseudo-code:
let importedValue : Optional Text =
http://www.example.com/foo as Optional <|> /etc/foo as Optional <|> env:FOO as Optional
in let finalValue = Optional/fold Text importedValue Text (λ(x : Text) → x) "{foo not found}"
in finalValue
from dhall-lang.
I was also wondering about this, but I'm conflicted about the matter:
- having the program fail if the envvar is not there makes it safer, because you have to consciously provide it, and it will not just silently run without the possibly critical value.
- however:
- it's really nice to be able to not make the program fail for some non-critical value for which we can give defaults
- it's really nice to be able to branch at runtime based on the presence of an envvar or not
So I'm not sure we should actually go for this, but in case we want to:
I propose that we add the envOpt
prefix for returning an optional envvar.
Could look something like this:
-- suppose our ENV looks like this:
-- - var A set to "λ(a : Bool) → if a then 1 else 2"
-- - var B not set
-- - var C set to "Some text"
{ a = envOpt:A as Optional (∀(a : Bool) → Integer)
, b = envOpt:B as Optional (∀(a : Bool) → Integer)
, c = envOpt:C as Optional Text
}
-- then the return value would be:
{ a = ([ λ(a : Bool) → if a then 1 else 2 ] : Optional (∀(a : Bool) → Integer))
, b = ([] : Optional (∀(a : Bool) → Integer))
, c = ([] : Optional Text)
}
In this way we would have both possibilities of throwing in case the var is compulsory (with env
), but also make it possible to make a variable optional (with envOpt
).
from dhall-lang.
@f-f: I have a proposal for how to do this here: #163
from dhall-lang.
Related Issues (20)
- Time/Date arithmetic
- Reflection or converting types to values HOT 2
- Cannot Decode Expression with extended Builtin Function HOT 1
- Q. Are you interested in syntax diagrams for Dhall? HOT 6
- Reversing order of Merge and Selection? HOT 2
- Too many duplicate type annotations? HOT 2
- `with` record update syntax removes other record fields HOT 4
- ABNF grammar should list "as Bytes" import mode
- Should the ABNF grammar disallow shebangs inside expressions? HOT 1
- eta-reducing to merge HOT 4
- Builtins operators reference: Missing record projection HOT 2
- ABNF grammar should explicitly disallow keywords as identifiers? HOT 2
- ABNF grammar should include a mandatory whitespace after `import-hashed`? HOT 1
- Improvements and fixes in the standard documentation HOT 3
- Is this an incorrect test file: `dhall-lang/tests/import/success/unit/ImportRelativeToHomeB.dhall`? HOT 2
- Link to non existing tweet
- A minimalistic proposal for do-notation
- Thoughts on introducing a minimum amount of type inference in Dhall HOT 1
- Introduce Bytes/length and Text/length as built-ins? HOT 3
- Is there a security hole: malicious sha256-protected cached content? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dhall-lang.