Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize Natural/fold in the strict case #2585

Merged
merged 9 commits into from
Jun 12, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dhall/src/Dhall/Normalize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,13 @@ normalizeWithM ctx e0 = loop (Syntax.denote e0)
strict = strictLoop (fromIntegral n0 :: Integer)
lazy = loop ( lazyLoop (fromIntegral n0 :: Integer))

strictLoop 0 = loop zero
strictLoop !n = App succ' <$> strictLoop (n - 1) >>= loop
strictLoop !n = strictLoopShortcut n (loop zero)
strictLoopShortcut 0 !res = res
strictLoopShortcut !n !res = do
x <- res
let next_res = App succ' <$> res >>= loop
y <- next_res
if judgmentallyEqual x y then res else strictLoopShortcut (n - 1) next_res
winitzki marked this conversation as resolved.
Show resolved Hide resolved

lazyLoop 0 = zero
lazyLoop !n = App succ' (lazyLoop (n - 1))
Expand Down
Loading