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

Misc coding styles and niche optimizations #32

Open
6 of 9 tasks
Tracked by #4
toyboot4e opened this issue Nov 10, 2024 · 0 comments
Open
6 of 9 tasks
Tracked by #4

Misc coding styles and niche optimizations #32

toyboot4e opened this issue Nov 10, 2024 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@toyboot4e
Copy link
Owner

toyboot4e commented Nov 10, 2024

Newer style

  • Replace return with pure
  • Replace fmap with <$>

Associated modulus values

  • GHC.TypeLits vs GHC.TypeNats
    Prefer the latter, which requires less type conversion from Nat.
  • KnownNat vs AllowAmbiguousTypes vs Tagged
    Prefer KnownNat for simplicity.

Performance

  • Index iteration: VU.forM_ (VU.generate n id) vs forM_ [0 .. n - 1]
    Latter was a bit faster on AtCoder, even beter than to Bundle, although there's slow for_ warnings.
  • corece vs newtype constructors
    Prefer newtype constructors that helps us with typing. There's no performance difference (probably).
  • Reverse vector iteration: for [n - 1, n - 2 .. 0] vs foldr'
  • Folding sequence: vector (VU.foldM'_ f s (VU.generate n id)) vs list (foldM_ f s [0 .. n - 1])
  • Vector initialization: replicate + copy, unsafeNew + copy + manual filling vs grow -> manual filling
toyboot4e added a commit that referenced this issue Nov 14, 2024
@toyboot4e toyboot4e reopened this Dec 2, 2024
toyboot4e added a commit that referenced this issue Dec 3, 2024
@toyboot4e toyboot4e changed the title Misc coding styles Misc coding styles and niche optimizations Dec 8, 2024
@toyboot4e toyboot4e added the help wanted Extra attention is needed label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant