It would be nice to pretty print the types and values when invoking the binary with the --explain flag.
The current output is pretty confusing and hard to debug. Example when getting wrong some dhall-kubernetes type:

Additionally, in cases of type mismatch (like the one I have above), it would be great to have the diff of the mismatched type (interestingly, when not using the --explain flag both things happen: there is a diff and it's pretty printed)
I have the fix to the first part (pretty-printing expressions) ready here: https://github.com/dhall-lang/dhall-haskell/pull/429
@f-f: Also, the detailed error messages do include the type diff. It's just located at the top of the error, like this:
$ dist/build/dhall/dhall --explain <<< '[1, True]'
Error: List elements should all have the same type
- Natural
+ Bool
Explanation: Every element in a list must have the same type
For example, this is a valid β°Listβ±:
βββββββββββββ
β [1, 2, 3] β Every element in this β°Listβ± is a β°Naturalβ± number
βββββββββββββ
.. but this is not a valid β°Listβ±:
βββββββββββββββββ
β [1, "ABC", 3] β The first and second element have different types
βββββββββββββββββ
Your first β°Listβ± element has this type:
β³ Natural
... but the element at index #1 has this type instead:
β³ Bool
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
True
(stdin):1:5
So I think this issue is done
Oh right sorry (I usually run things on 1.11 for CI reasons, as it's the one on stackage stable).
Thanks for the fix!
However, even on latest master the diff for type mismatch in records is not clear, as it doesn't show the current "wrong" type, as it happens instead in your example above.
E.g. let's say I have a record { a : Optional Text }; if I do something like this:
dhall --explain <<< '{ a = [] : Optional Text} // { a = "foo"} : { a : Optional Text }'
There at the top I'll get:
Error: Expression doesn't match annotation
{ a : - β¦ β¦
+ Text
}
I think something like this would be more clear:
{ a : - Optional Text
+ Text
}
@f-f: I actually have a branch that fixes that which I've been working on so that it fully displays "small" types/values in diffs
@f-f: So what I will probably implement is an intermediate solution, which is to special-case rendering the skeleton of Optional β¦ and List β¦
The issue with fully rendering the skeleton of an App constructor is that there's no limit on how deeply nested the App could be if you have a function applied to a large number of arguments and skeleton is designed to produce an output of bounded size. That's why I'm just special-casing it to one-level deep display of List/Optional for now
Alright, that pull request is merged. Give it a test drive and let me know if that works for you
Now my example from above works nicely:
./dhall --explain <<< '{ a = [] : Optional Text} // { a = "foo"} : { a : Optional Text }'
Error: Expression doesn't match annotation
{ a : - Optional β¦
+ Text
}
It's not as explicit as I envisioned above (Optional ... vs Optional Text), but I think the tradeoff of displaying only one level is good, so I'd consider this issue resolved.
Thanks a lot @Gabriel439!
@f-f: You're welcome! π
Most helpful comment
@f-f: I actually have a branch that fixes that which I've been working on so that it fully displays "small" types/values in diffs