Comments (21)
What is the motivation for providing support for environment variables, though? The reason I ask is that any program that takes environment variables implicitly could be done by reformulating the program as a function. For example, your code could be written as:
λ(ENV : { FOO : Text, BAR : Text })
→ { foo = ENV.BAR }
... and instead of running:
$ FOO=foo BAR=bar dhall <<< './example'
... you could supply the desired variables as an ordinary function argument when invoking the expression:
$ dhall <<< './example { FOO = "foo", BAR = "bar" }'
... or if you are really constrained to obtain the values from environment variables, you could even do:
$ dhall <<< "./example { FOO = \"${FOO}\", BAR = \"${BAR}\" }"
from dhall-haskell.
No. Dhall can only import values via file paths or URLs
from dhall-haskell.
Do you see handling of environment variables as something that should be external do Dhall?
from dhall-haskell.
Actually, I could add support for reading in Dhall expressions via environment variables, using something like this syntax:
{ foo = ${BAR}
}
However, there are two issues with that:
-
I might want to reserve the same syntax for interpolating
Text
into a string literal, like this:let txt = "Hello" in "${txt} world!"
... and it might be confusing to use the same syntax in two different ways
-
Imported environment variables would have to be valid Dhall expressions, meaning that if you
wanted to importText
, then you'd have to define the environment variable like this:EXAMPLE='"Test"'
from dhall-haskell.
I can see your point.
What if there was an implicit global let
binding that has all the environment variables in them as strings?
For example:
{ foo = ENV.BAR
}
would imply:
let ENV = { BAR = <string-value-of-BAR> } in
{ foo = ENV.BAR
}
from dhall-haskell.
In the last case, it will mostly work except when the environment variable needs to be escaped, which is the tricky bit.
Perhaps all we need is a env-to-dhall
command line tool that does all the necessary escaping?
dhall <<< "λ(ENV : $(env-to-dhall)) → { foo = ENV.BAR }"
Or:
dhall <<< "λ(ENV : $(env-to-dhall)) → ./config"
from dhall-haskell.
Hmmm. I would prefer reading environment variables directly within Dhall as a built-in mechanism rather than provide an env-to-dhall
executable
The main issue with env-to-dhall
or an Env
record in general is that dhall
does not allow records to hold fields which are types or kinds. So if one of your environment variables is a type or kind you will get a type error when type-checking the Env
record
The second issue (when I thought about this more) is that an env-to-dhall
mechanism does not support transitively resolving environment variables. In other words, if an environment variable references another environment variable then Dhall should support that (and do basic cycle checking like it does for files/URLs).
So what I'll probably do is add something like env://FOO
to reference the environment variable FOO
in Dhall. However, FOO
will need to be a valid Dhall expression, meaning that if you want to import a Text
string then the contents of FOO
need to be quoted.
So in other words, you could do:
$ FOO='"foo"' BAR='1' dhall <<< '{ foo = env://FOO , bar = env://BAR }'
{ bar : Integer, foo : Text }
{ bar = 1, foo = "foo" }
How does that sound?
from dhall-haskell.
That sounds really good.
Although being able embed variables as string is also useful. I don't mind having to type extra to get it. For example, I'd be happy with env+text://FOO
. Even file+text://pubrung.gpg
would be helpful too.
from dhall-haskell.
I just realized that env://FOO
is a misleading URI since it implies that FOO
is the authority as opposed to the path. It seems like env:FOO
is the more appropriate URI
I also like the idea of using +text
in the scheme to denote that we expect unquoted Text
. I'll implement that, too
from dhall-haskell.
Good spot. Thanks!
from dhall-haskell.
Alright, the first part of this is done in 11ceab1 (supporting env:NAME
syntax). The env+text
and file+text
support will come in a subsequent commit
from dhall-haskell.
Looking good!
from dhall-haskell.
I just discovered a case that might need better dhall
support:
circle-cli-exe:
↳ ./project.config
Error: Invalid input
project.config:1:17: error: expected: "''",
"(", "+", "-", "[", "\8704",
"\955", "\\", "forall", "if",
"let", "merge", built-in value,
double, import, integer, label,
list literal, natural,
record literal, record type,
string, union literal,
union type
{ environment = ~/.circle/project-config/haskell-works.config
^
from dhall-haskell.
At the moment, I'm required to put the absolute path in:
{ environment = /Users/jky/.circle/project-config/haskell-works.config
}
from dhall-haskell.
Could I propose an alternative syntax for importing raw Text
? I was thinking of adding an as Text
suffix to the path in order to import it as a raw Text
literal, like this:
{ foo = /foo as Text
, bar = env:HOME as Text
, baz = http://example.com as Text
}
Would that be alright?
from dhall-haskell.
I put up a PR for the as Text
proposal here: #34
from dhall-haskell.
👍
from dhall-haskell.
Thanks so much!
from dhall-haskell.
You're welcome! :)
from dhall-haskell.
This is actually a very nice feature to manage global cross cutting concerns nicely. This makes it very powerful, especially since it is also evaluating file imports. Great job!
from dhall-haskell.
@feliksik: Thanks 🙂
from dhall-haskell.
Related Issues (20)
- Failure to Decode Expression with extended Builtin Function HOT 1
- Document the significance of `Nothing :: Maybe CharacterSet`
- Please report symlink contents for `Error: Missing file` HOT 2
- Error generating docs
- combine `let` bindings in `dhall format` HOT 1
- Support request for `aeson` 2.2 in `dhall` HOT 2
- dhall-to-yaml does not properly quote strings HOT 1
- Can not install dhall-lsp-server HOT 2
- Allow hnix 0.17
- Hackage build failed for dhall-toml-1.0.3
- Get back into Stackage Nightly with GHC 9.8 HOT 1
- Missing binaries in release HOT 1
- Hackage release for dhall-lsp-server HOT 1
- Build failure on GHC 9.8.1: 'Illegal invisible type variable binder'
- Report imports HOT 1
- dhall-docs: Prelude.head: empty list
- Suggesting a new construct for dealing with optional fields in Dhall defaults
- dhall-json bound on aeson can be relaxed
- Questions regarding the right strategy for upgrading to ghc-9.8
- Build failure on macos-latest stack.yaml HOT 3
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-haskell.