While toying with an idea for a new area to use Dhall, I made a simple Ratio
type with associated math functions, and a Haskell program that expects to be provided with functions of type Ratio -> Ratio -> Ratio
. This all appears to work when executed, but produces absolutely enormous and slow to compute normal forms when even simple expressions are just passed to dhall.
As an example: a function to compare a ratio with the average of a list of ratios produces an expression which will completely freeze my computer for many minutes before it renders.
The culprit appears to be branches inside the math functions, as I can remove some cases and reduce the size by an order of magnitude or more. The most significant of these being a condition that checks if the denominators of two ratios are equal to avoid multiplying them every time.
Is there a good way to avoid this? I can make the provided functions in Dhall take the record of possible math operations on Ratios as the first argument, but that’s not exactly ideal