Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#1189 closed proposal (fixed)

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 (3)

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

Download all attachments as: .zip

Change History (7)

Changed 7 years ago by jyasskin

Changed 7 years ago by jyasskin

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

Changed 7 years ago by jyasskin

Haddock'ed docs from V2

comment:1 Changed 7 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

comment:2 Changed 7 years ago by igloo

  • Resolution set to fixed
  • Status changed from new to closed

Patch applied, thanks!

comment:3 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:4 Changed 6 years ago by simonmar

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