Add Natural/equal and Natural/lessThan primitives#2739
Conversation
|
The CI fails because it relies on a submodule dependency on Prelude from https://github.com/dhall-lang/dhall-lang. I have made the required PR there for the tests to pass. This submodule dependency is actually recursive, because the mentioned PR also has a breaking CI due to a dependency on this repo. I see several ways of addressing this:
|
|
In my view, there is not a lot of benefit in adding lots of primitives. The real problem is the general blowup of normal forms, which is a property of the pure λ-calculus (System Fω) which Dhall implements. In λ-calculus, the beta-normal form must always evaluate under lambda, and this means no Adding primitives for |
|
I agree that normal form caused memory blow up is a major problem and that even with these added primitives it persists due to other reasons. However I suggest reviewing these primitives in isolation from the memory blow up problem because they are useful for performance regardless. Subtracting one-by-one down to zero for comparison is just terrible for performance regardless of the ASTs. |
|
Yeah, the current system is not a great system. Normally the sequencing I would use in the past was:
I'm open to fixes/improvements to that. Generally, my intuition is that whatever process we design should treat One possible way to fix that would be to expand the
If we were to go that route the main engineering work involved would be to implement enough of the semantics to resolve, type check, normalize, and pretty-print the Prelude. The big current omissions in the standard semantics (if I remember correctly) are import resolution and pretty-printing. |
|
Also, regarding builtins, I think we should err on the side of having more builtins (although we should still choose them judiciously) rather than relying on implementations to be clever optimizers. My reasoning is that
In particular, pattern matching and optimizing against a specific normal form might not work if the expression is evaluated in the wrong order. As a concrete example, suppose we have a contrived optimization that recognizes an expression of the form: λ(x : T) → e₀… and optimizes it to something more efficient. We run the risk of an expression like this: (λ(x : T) → e₀) e₁… being evaluated in the wrong order and reduced to: e₀[x := e₁]… before the optimization triggers. While any given implementation might not get that wrong, I'd be concerned about all implementations avoiding that potential performance pitfall. |
I'm not sure I follow this. I am not aware that there is another implementation of Dhall within If we are talking about the documentation in dhall-lang then indeed the import system is not as fully documented as the semantics. At some point I started to rewrite the standard document about the import system, but I didn't complete that work. If that's interesting I could go back to that. |
Comparison of I would also like to try refactoring the existing dhall-haskell code around primitives, so that it becomes much easier to add and maintain new primitives. At the moment there are lots of different places where code must be added to support a new primitive. |
How about merging these into a monorepo? The current recursive dependency structure proves that these repositories are coupled. Also if we assume that the tooling around the language standard (all the standard executables) needs to always be in sync with the standard (which seems reasonable) it becomes only natural for them to be versioned and controlled in the same space. This will also let us resolve the highlighted problems of the current distribution system pretty easily. |
This majorly addresses the issue of AST and memory consumption blow up in algorithms relying on those functions.
This fixes some problems discovered in dhall-lang/dhall-lang#1420.