primitive
primitive copied to clipboard
foldMap, foldMap' for PrimArray
I'm good with this. If there aren't any objection in the next few days, I'll merge this.
No objections here, although these deserve to be mentioned in the changelog.
Sorry I keep forgetting that. I'll add it in.
Is this good to be merged? The travis failure is unrelated.
Sorry for the delayed review
That is okay, this is valuable feedback. I will make these changes shortly.
most recent commit does not add balanced foldMap. I think I'd prefer for that to be in a separate PR, as it's a little more complicated.
requested changes attempted, @treeowl
Both examples are supposed to show associativity. I think they can be much briefer, TBH. Just give a three-element example application and show how it unfolds as a single expression.
On Mon, Sep 17, 2018, 9:54 PM chessai [email protected] wrote:
@chessai commented on this pull request.
In Data/Primitive/PrimArray.hs https://github.com/haskell/primitive/pull/186#discussion_r218279364:
+-- +-- @mySum = 'Data.Monoid.getSum' '$' ('Data.Monoid.Sum' 1 '<>' ('Data.Monoid.Sum' 2 '<>' ('Data.Monoid.Sum' 3 '<>' 'Data.Monoid.Sum' 4)))@ +-- +-- @mySum = 'Data.Monoid.getSum' '$' ('Data.Monoid.Sum' 1 '<>' ('Data.Monoid.Sum' 2 '<>' ('Data.Monoid.Sum' 7)))@ +-- +-- @mySum = 'Data.Monoid.getSum' '$' ('Data.Monoid.Sum' 1 '<>' ('Data.Monoid.Sum' 9)@ +-- +-- @mySum = 'Data.Monoid.getSum' '$' 'Data.Monoid.Sum' 10@ +-- +-- @mySum = 10@ +foldMapRPrimArray :: forall a m. (Prim a, Monoid m) => (a -> m) -> PrimArray a -> m +{-# INLINE foldMapRPrimArray #-} +foldMapRPrimArray f = foldrPrimArray (\a acc -> f a
mappendacc) mempty
+-- | Map each element of the primitive array to a monoid, and combine the results. +-- The combination is left-associated, and the accumulation is lazy.
Clarification: Are you asking to provide an example for foldMapLPrimArray, to show left-associativity (for this particular lazy fold)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/haskell/primitive/pull/186#discussion_r218279364, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_V_eja4orM-34lJJs1TwInJE6ERrks5ucFJVgaJpZM4VQDt8 .
Both examples are supposed to show associativity. I think they can be much briefer, TBH. Just give a three-element example application and show how it unfolds as a single expression.
By 'briefer', do you mean less 'tutorial-like', to assume that the example is illustrative enough sans written explanation?
By 'briefer', do you mean less 'tutorial-like', to assume that the example is illustrative enough sans written explanation?
Right. This is primitive, not base or containers. Users are expected to know what they're doing. But language is slippery, so "associates to the left" might well evoke opposite meanings in the minds of two different people.
Right. This is primitive, not base or containers. Users are expected to know what they're doing. But language is slippery, so "associates to the left" might well evoke opposite meanings in the minds of two different people.
Makes sense - understood
Aha! I've changed my mind :). I believe we should force each function value in the strict versions. Laziness here is kind of silly, but more to the point, I believe the laziness reveals semantic differences in fold associativity that are only supposed to be performance differences.
On Mon, Sep 17, 2018, 10:17 PM chessai [email protected] wrote:
Right. This is primitive, not base or containers. Users are expected to know what they're doing. But language is slippery, so "associates to the left" might well evoke opposite meanings in the minds of two different people.
Makes sense - understood
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/haskell/primitive/pull/186#issuecomment-422230980, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_a3CzXzv1s-TcI2ZeePIIZX1mptbks5ucFe5gaJpZM4VQDt8 .
@treeowl Examples are now simplified and function values are being forced
Humor me and check whether what I said about forcing is really true. I was going off intuition.
On Mon, Sep 17, 2018, 10:53 PM chessai [email protected] wrote:
@treeowl https://github.com/treeowl Examples are now simplified and function values are being forced
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/haskell/primitive/pull/186#issuecomment-422236769, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_VlFO4Cj6buIYDs2COP8-OJAPoAPks5ucGASgaJpZM4VQDt8 .
OK
I like the stuff in the PR, although I dislike the naming convention that @treeowl suggested. I actually prefer foldrMapPrimArray to foldMapRPrimArray. Anyone else got any thoughts on the color of the bikeshed?
I would still like this and also a foldl for ByteArray at some point. Happy to help to make that happen in whatever way I can.
I'll change the names and merge this. @Boarders Open a separate PR for a foldl on ByteArray. You should be able to nearly copy and paste the foldl on PrimArray.