Ticket #1189 (closed proposal: fixed)

Opened 6 years ago

Last modified 5 years ago

Add First and Last wrappers around Maybe to Data.Monoid

Reported by: jyasskin Owned by:
Priority: normal Milestone: Not GHC
Component: libraries/base Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

First and Last mappend to the first and last non-Nothing elements of the input. These instances seem to fit with the other simple instances in this file and are useful, for example, to turn foldMap into findFirst or findLast, or to get a really trivial Writer monad.

Attachments

FirstLastMonoids.patch Download (47.9 KB) - added by jyasskin 6 years ago.
MaybeMonoids.patch Download (50.2 KB) - added by jyasskin 6 years ago.
V2 of the First and Last monoids, now with an instance for Maybe itself.
Data-Monoid.html Download (28.6 KB) - added by jyasskin 6 years ago.
Haddock'ed docs from V2

Change History

Changed 6 years ago by jyasskin

Changed 6 years ago by jyasskin

V2 of the First and Last monoids, now with an instance for Maybe itself.

Changed 6 years ago by jyasskin

Haddock'ed docs from V2

Changed 6 years ago by jyasskin

Ross Paterson suggested that the "obvious" instance directly on Maybe was to combine two Just's using a Monoid instance on their contents and set mempty==Nothing. David House, Stefan O'Rear, and Jan-Willem Maessen agreed so I added it.

John Meacham objected to the location of all of the types currently in Data.Monoid, but that's a broader discussion than this patch, and nobody expressed agreement anyway.

David Menendez and Spencer Janssen suggested that Maybe's Monoid instance should match its MonadPlus? instance, but neither provided an argument supporting that.

The thread is archived at  http://www.haskell.org/pipermail/libraries/2007-March/006950.html

Changed 6 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Patch applied, thanks!

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.