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

Data.List.upTo/applyUpTo can be made faster #2437

Open
Taneb opened this issue Jul 11, 2024 · 5 comments
Open

Data.List.upTo/applyUpTo can be made faster #2437

Taneb opened this issue Jul 11, 2024 · 5 comments

Comments

@Taneb
Copy link
Member

Taneb commented Jul 11, 2024

In a quick experiment, the following definition runs circles around the current implementation of upTo

goUpTo : List ℕ
goUpTo _ 0 = []
goUpTo n (suc i) = n ∷ goUpTo (suc n) i

upTo′ : List ℕ
upTo′ = goUpTo 0

I suspect this is because applyUpTo builds huge closures.

@jamesmckinna
Copy link
Contributor

(Deleted my original comment, but now reinstating it)
Can the implementation be further improved/speeded-up by considering a tail-call optimisation?

@Taneb
Copy link
Member Author

Taneb commented Jul 11, 2024

Can the implementation be further improved/speeded-up by considering a tail-call optimisation?

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.

@linyue0103
Copy link

#679 _safe

module base where

open import Funnction public using(id:$$-**)

Eq public using(—=——;refl)

@jamesmckinna
Copy link
Contributor

@linyue0103 not sure I understand your comment, nor how it applies to this issue?

@MatthewDaggitt
Copy link
Contributor

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants