-
Notifications
You must be signed in to change notification settings - Fork 60
add strict map functions for Array and SmallArray #138
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
Conversation
| let go i | i == sizeofArray a | ||
| = return () | ||
| | otherwise | ||
| = do x <- indexArrayM a i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth mentioning in a comment that we use indexArrayM here in case f is lazy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
| #if HAVE_SMALL_ARRAY | ||
| mapSmallArray' f sa = createSmallArray (length sa) (die "mapSmallArray'" "impossible") $ \smb -> | ||
| fix ? 0 $ \go i -> | ||
| when (i < length sa) $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why < here and == for Array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure. I just copied the implementation of fmap for SmallArray to get this. I think the better question is why does everything in SmallArray use fix while everything in Array uses explicit recursion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
History, I imagine. The fix seems to avoid the need for a local type signature in the go function. I have no idea how the generated code compares, but that would be worth checking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm inclined to leave this as is for now. I'd like to open a separate PR adding benchmarks that check the difference between these two styles.
|
I cut down and reworded the comment. There are two reasons to want to perform the lookup eagerly, and this is not the place to explain that. Aside from holding references to the array, we don't want to build a thunk to perform the lookup. |
|
Your wording is certainly more concise. Thanks! |
No description provided.