-
Notifications
You must be signed in to change notification settings - Fork 242
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
Data.List.upTo/applyUpTo can be made faster #2437
Comments
(Deleted my original comment, but now reinstating it) |
I don't think so. The recursion here is already guarded behind a constructor. I don't know what a tail recursive implementation would look like. |
Yes, I never had performance in mind when I add any of my definitions. Apologies! There's probably plenty more of these lurking in the library... |
So...: instead have upTo : ℕ → List ℕ
upTo = go 0
module UpTo where
go : ℕ → ℕ → List ℕ
go _ zero = []
go n (suc i) = n ∷ go (suc n) i
downFrom : ℕ → List ℕ
downFrom zero = []
downFrom (suc n) = n ∷ downFrom n to avoid building the closures in
Not clear what the knock-on effects on |
In a quick experiment, the following definition runs circles around the current implementation of
upTo
I suspect this is because
applyUpTo
builds huge closures.The text was updated successfully, but these errors were encountered: