Skip to content

Add rnfFoldableLTR and rnfFoldableRTL#18

Closed
treeowl wants to merge 1 commit into
haskell:masterfrom
treeowl:rnfFoldable
Closed

Add rnfFoldableLTR and rnfFoldableRTL#18
treeowl wants to merge 1 commit into
haskell:masterfrom
treeowl:rnfFoldable

Conversation

@treeowl

@treeowl treeowl commented Jul 17, 2016

Copy link
Copy Markdown
Contributor

If a type has a Foldable instance, then we can force it from
left to right or from right to left.

Fixes #17

If a type has a `Foldable` instance, then we can force it from
left to right or from right to left.

Fixes haskell#17
@RyanGlScott

Copy link
Copy Markdown
Member

For context: Haskell libraries mailing list discussion: https://mail.haskell.org/pipermail/libraries/2016-July/027164.html

@rwbarton

Copy link
Copy Markdown

This should carry a huge warning that it is normally not a sensible definition for Foldable instances where f a contains fields of types other than a, such as a pair.

@treeowl

treeowl commented Jul 27, 2016

Copy link
Copy Markdown
Contributor Author

It has such a warning, specifically mentioning Either a and (,) a. Is
the warning insufficient?

On Jul 27, 2016 5:03 PM, "Reid Barton" notifications@github.com wrote:

This should carry a huge warning that it is normally not a sensible
definition for Foldable instances where f a contains fields of types
other than a, such as a pair.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#18 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABzi_djQZ4CsXZJuz8q7fJP_0C8XJgpyks5qZ8esgaJpZM4JOIet
.

@rwbarton

Copy link
Copy Markdown

Oh, so it does. There is such a lot of noise in the diff that I missed it.

Comment thread Control/DeepSeq.hs

instance Monoid UnitLTR where
mempty = UnitLTR ()
UnitLTR () `mappend` y = y

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To avoid invoking the wrath of -Wnoncanonical-monoid-instances in later GHCs, it'd be prudent to define mappend like this:

instance Monoid UnitLTR where
  mempty = UnitLTR ()
#if MIN_VERSION_base(4,9,0)
  mappend = (<>)
#else
  UnitLTR () `mappend` y = y
#endif

And similarly for UnitRTL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@chessai

chessai commented May 3, 2019

Copy link
Copy Markdown
Member

This seems useful, can this be worked in to the modern deepseq?

@cartazio

cartazio commented May 4, 2019 via email

Copy link
Copy Markdown

@chessai

chessai commented Dec 29, 2019

Copy link
Copy Markdown
Member

Are we worried at all about the loss of Safe?

@mixphix

mixphix commented Aug 25, 2024

Copy link
Copy Markdown
Collaborator

foldMap can be more efficient than either foldl or foldr, so Unit was added by #106 (same as UnitLTR).

@mixphix mixphix closed this Aug 25, 2024
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.

Offer Foldable helper

7 participants