Skip to content

Attempting some stack safety strategies #2

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

Open
wants to merge 2 commits into
base: nub-ord-bench
Choose a base branch
from

Conversation

milesfrain
Copy link
Owner

nubBy's stack safety issue appears to be caused by nubByAdjacentReverse, but that function is stack safe on it's own.

@@ -860,7 +880,10 @@ foldM f b (a : as) = f b a >>= \b' -> foldM f b' as
-- |
-- | Running time: `O(n)`
mapReverse :: forall a b. (a -> b) -> List a -> List b
mapReverse f = go Nil
mapReverse f l = reverse $ map f l
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using this slower, but definitely stack safe alternative (not saying the other version is stack unsafe, but just trying to eliminate unknowns).

@@ -876,7 +899,10 @@ mapReverse f = go Nil
-- |
-- | Running time: `O(n)`
addIndexReverse :: forall a. List a -> List (Tuple Int a)
addIndexReverse = go 0 Nil
addIndexReverse = reverse <<< mapWithIndex Tuple
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be stack safe too, right?

@milesfrain milesfrain mentioned this pull request Jan 13, 2021
@milesfrain milesfrain force-pushed the nub-ord-bench-stacksafe branch from b7b3690 to 8bae586 Compare January 13, 2021 06:33
benchLists "nubBySafe" $ nubBySafe compare -- safe
benchLists "addIndexReverse" addIndexReverse -- safe
benchLists "mapReverse" $ mapReverse $ add 1 -- safe
benchLists "sortBy" $ sortBy compare -- NOT SAFE!!!!
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem

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

Successfully merging this pull request may close these issues.

1 participant