-
Notifications
You must be signed in to change notification settings - Fork 60
More eagerness #96
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
More eagerness #96
Conversation
`fmap` for `Array` got its indexing all wrong. Fix that. `>>=` for `Array` went into an infinite loop (haven't investigated why). Replace its implementation with the working `SmallArray` one. Fixes haskell#92 and haskell#95
* Perform array indexing eagerly in general to avoid useless thunks. * Make `munzip` stricter for `Array`, to match the `SmallArray` instance and avoid loads of thunks. * Give `Array` and `SmallArray` much less inefficient `MonadFix` instances. Leaning on the instance for `[]` is bad because indexing into lists is expensive, and that's effectively what the `MonadFix` instance does.
|
Looks promising. One thing that's a bit unclear to me: a lot of these changes involve replacing uses of |
|
I'm not really sure how to formulate a general rule. case indexArray## ar j of
(# x #) -> f xsays "Get the |
RyanGlScott
left a comment
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.
Gotcha. If there's not a hard-and-fast rule for when to use it, it's perhaps not worth trying to enshrine in the documentation, then.
Other parts look good to me. I've left one suggestion inline.
| some sa | null sa = emptySmallArray | ||
| | otherwise = die "some" "infinite arrays are not well defined" | ||
|
|
||
| data ArrayStack a |
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.
Is it possible to reuse this datatype across both SmallArray.hs and Array.hs? My (entirely untested) hypothesis is that you could turn this into:
data ArrayStack f a
= PushArray !(f a) !(ArrayStack a)
| EmptyStackand put this somewhere in Data.Primitive.Internal.
|
I haven't exposed |
I must be missing something, as your current version doesn't |
|
I believe GHC has automatically unboxed small strict fields (i.e., word-sized ones) by default since 7.8. |
|
Oops, I totally forgot that |
Perform array indexing eagerly in general to avoid
useless thunks.
Make
munzipstricter forArray, to match theSmallArrayinstance and avoid loads of thunks.Give
ArrayandSmallArraymuch less inefficientMonadFixinstances. Leaning on the instance for[]is bad because indexing into lists is expensive, and that's
effectively what the
MonadFixinstance does.