Giter Site home page Giter Site logo

Comments (3)

Gabriella439 avatar Gabriella439 commented on June 25, 2024 1

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.

f-f avatar f-f commented on June 25, 2024

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.

Gabriella439 avatar Gabriella439 commented on June 25, 2024

@f-f: I have a proposal for how to do this here: #163

from dhall-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.