Ticket #3335 (closed proposal: fixed)

Opened 4 years ago

Last modified 4 years ago

make some Applicative functions into methods, and split off Data.Functor

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

Description

The following functions

(<$) :: Functor f => a -> f b -> f a 
(*>) :: Applicative f => f a -> f b -> f b 
(<*) :: Applicative f => f a -> f b -> f a 
some :: Alternative f => f a -> f [a]
many :: Alternative f => f a -> f [a]

are moved into the corresponding classes, with the existing implementations as default definitions. This gives people creating instances the option of defining specialized implementations of these functions, though they should be equivalent to the default definitions.

Although (<$) is now a method of the Functor class, it is hidden in the re-export by the Prelude, Control.Monad and Monad. The new module Data.Functor exposes the full class, plus the function (<$>). These are also re-exported by Control.Applicative.

Discussion on libraries@… to 20th July 2009.

Attachments

ApplicativeMethods.patch Download (7.2 KB) - added by ross 4 years ago.
patch
ApplicativeMethods.2.patch Download (7.2 KB) - added by ross 4 years ago.
patch

Change History

Changed 4 years ago by ross

patch

Changed 4 years ago by ross

patch

Changed 4 years ago by igloo

  • difficulty set to Unknown
  • milestone set to Not GHC

Changed 4 years ago by ross

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

There was substantial discussion by 8 people over 2 months.

* Making these methods redefinable allows significantly more efficient implementations for some instances (e.g. (<$) for Seq, (*>) and (<*) for parsers Edward Kmett is working on, some and many for first/empty calculations for recursive descent parsers). The same could be achieved by RULES, but these are GHC-only, and relying on the optimizer for asymptotic improvements is dangerous.

* Other functions were suggested for the same treatment, but they can be left to another proposal: (**), liftA2 and pair (= liftA2 (,)).

Note: See TracTickets for help on using tickets.