If I have a Prelude.dhall containing the following:
https://raw.githubusercontent.com/dhall-lang/dhall-lang/v7.0.0/Prelude/package.dhall
Then dhall freeze errors out:
$ dhall freeze --inplace Prelude.dhall
Use "dhall --explain" for detailed errors
_ : Bool
_ : Type
_ : _@2
_ : _@2
Error: Invalid predicate for β°ifβ±
This happens with the latest release 1.22.0 and on master. Also the error with --explain is not much more helpful than this one
Actually the issue seems to be that the deserialization doesn't roundtrip: putting a hash on the above import works the first time you evaluate the expression, but not the second (because it deserializes from the cache)
@f-f: It would still help me to see the error message with --explain
@Gabriel439 right sorry, here it is:
$ dhall --explain <<< "./Prelude.dhall"
_ : Bool
_ : Type
_ : _@2
_ : _@2
Error: Invalid predicate for β°ifβ±
Explanation: Every β°ifβ± expression begins with a predicate which must have type
β°Boolβ±
For example, these are valid β°ifβ± expressions:
ββββββββββββββββββββββββββββββββ
β if True then "Yes" else "No" β
ββββββββββββββββββββββββββββββββ
β§
Predicate
βββββββββββββββββββββββββββββββββββββββββββ
β Ξ»(x : Bool) β if x then False else True β
βββββββββββββββββββββββββββββββββββββββββββ
β§
Predicate
... but these are not valid β°ifβ± expressions:
βββββββββββββββββββββββββββββ
β if 0 then "Yes" else "No" β β°0β± does not have type β°Boolβ±
βββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββ
β if "" then False else True β β°""β± does not have type β°Boolβ±
ββββββββββββββββββββββββββββββ
Some common reasons why you might get this error:
β You might be used to other programming languages that accept predicates other
than β°Boolβ±
For example, some languages permit β°0β± or β°""β± as valid predicates and treat
them as equivalent to β°Falseβ±. However, the Dhall language does not permit
this
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Your β°ifβ± expression begins with the following predicate:
β³ _@1
... that has type:
β³ _@2
... but the predicate must instead have type β°Boolβ±
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
where the Prelude.dhall has this content:
https://raw.githubusercontent.com/dhall-lang/dhall-lang/v7.0.0/Prelude/package.dhall sha256:c5cd3e107bb2579d60084d9f7caa93b20e6230eafba4d56ce6fba100be2bc066
I can narrow this down to ./Prelude/Bool/fold
Here's a reproduction that doesn't involve serialization:
$ dhall <<< './dhall-lang/Prelude/Bool/fold'
Ξ»(b : Bool)
β Ξ»(bool : Type)
β Ξ»(true : bool)
β Ξ»(false : bool)
β if b then true else false
$ dhall --alpha <<< './dhall-lang/Prelude/Bool/fold'
Ξ»(_ : Bool) β Ξ»(_ : Type) β Ξ»(_ : _) β Ξ»(_ : _@1) β if _@1 then _@1 else _
$ dhall --alpha <<< './dhall-lang/Prelude/Bool/fold' | dhall
Use "dhall --explain" for detailed errors
_ : Bool
_ : Type
_ : _@2
_ : _@2
Error: Invalid predicate for β°ifβ±
if _@1 then _@1 else _
(stdin):1:53
The bug appears to be due to the Ξ±-normalized form being incorrect. The reason it's triggered by serialization is due to serialization Ξ±-normalizing the expression. The next step is figuring out what is wrong with the Ξ±-normalization algorithm.
For reference, the Ξ±-normalized form should have been:
Ξ»(_ : Bool) β Ξ»(_ : Type) β Ξ»(_ : _) β Ξ»(_ : _@1) β if _@3 then _@1 else _
This seems to be my bug, I'll look at it shortly.
@Gabriel439 thanks a lot for narrowing it down! I opened https://github.com/dhall-lang/dhall-lang/pull/521 with this case as a regression test
Yeah, I can confirm that fcca883e00daadc377e784973f4121a28af659a0 is the commit that introduced this issue