I do not plan on learning haskell. Is it a prerequisite to learning dhall language?
Not at all, though some of the syntax is similar, and a general understanding of functional programming (not Haskell specifically) is useful. But it’s totally fine to not know/never learn Haskell; in fact, there are now bindings for Dhall available for many different languages, to say nothing of the ability to use the standalone CLI (which happens to be written in Haskell but is not “Haskell-y” in any way ).
I tried to understand when “in” is required. So far have not found any references to this keyword in the documentation. Can you explain when it’s needed?
A Dhall file consists of just a single expression (value). For example:
is valid Dhall (just the natural number zero).
However, we can assign any number of expressions to other identifiers to use in “building” that final expression, which uses
let ... in .... For example:
let myNumber = 0 -- This sets the identifier "myNumber" to the value "0"
myNumber -- This is the actual expression, which is the "value" the file will have
You can have more than one such binding, e.g.
let number1 = 1
let number2 = 2
number1 + number2 -- The value of the file is now 3
in is only required once to separate all of your
let bindings from whatever your final expression is.
This is also true within expressions, for example:
let number1 =
let number11 = 1 -- These are bindings "within" the expression we're setting number1 to
let number12 = 2
in number11 + number12 -- number1 will be 3
let number2 = 2
number1 + number2 -- Overall value is 3 + 2 == 5
Edit: I should note that the indentation/whitespace isn’t semantic here; I just wrote it that way for the sake of clarity. Dhall has a standard formatter (
dhall format) that will make things pretty, or at least what it thinks is pretty.
This is contrived, of course, but it is more useful when you’re defining functions.
Bottom line, you need an
in any time you are separating bindings (basically “variables”, if that intuition makes more sense from whatever your CS background is, though their values don’t vary) from the expression they are used in.
I tried first to join slack to ask questions there but the link https://functionalprogramming.slack.com/app_redirect?channel=dhall on the homepage is not an invite. Is it intended for dhall internal discussions? In general, what’s the best platform to ask newbie questions?
The Dhall channel on the FP slack is a fine place to ask questions.
Unfortunately, I can’t tell you why it’s not working, as I’m not involved with managing it. Edit: invite link posted in next message. But it’s not intended to be “internal” or anything, so I’m sure someone will sort it out for you.
If Discourse is the right place, maybe it’s worth adding a dedicated category for basic level questions to reduce noise from the main category?
This Discourse is pretttttyyyy quiet most of the time, so it shouldn’t be an issue, but definitely a good thought if the slack issue doesn’t get resolved/the Discourse gets more popular.