Ticket #3292 (closed proposal: fixed)

Opened 4 years ago

Last modified 3 years ago

Add an 'ignore' function to Control.Monad

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

Description

See  http://www.haskell.org/pipermail/libraries/2009-June/thread.html#11880

In short, add a 'ignore :: m a -> m ()' function to Control.Monad. This lets us do things like 'forkIO $ ignore stuff', as opposed to throwing around all sorts of '>> return ()'.

This function could be widely used by many libraries & apps, and has been repeatedly invented and suggested (see the thread). So far no one has said a word against it.

- -- | Convenience function. This is particularly good for 'forkIO' and 'forM_',
-- as they demand return types of 'IO ()', but most interesting IO functions
-- don't return void. So one can wrap them with 'ignore' (essentially a call to 'unit').
ignore :: Functor f => f a -> f ()
ignore = fmap (const ())

Attachments

ignore.dpatch Download (38.2 KB) - added by guest 4 years ago.
Patch adding ignore to base
void.dpatch Download (25.4 KB) - added by guest 3 years ago.
amended version; functor, name change, and more laconic documentation

Change History

Changed 4 years ago by guest

  • cc changed from gwern0@gmail.com to gwern0@gmail.com

Changed 4 years ago by guest

Patch adding ignore to base

Changed 4 years ago by dons

This is a generalization of the well-known FFI 'void' function:

module Foreign.Marshal.Error 

-- |Discard the return value of an 'IO' action
--
void     :: IO a -> IO ()
void act  = act >> return ()

in base for the last decade. Generalising 'void' (with that name), seems more intuitive to me.

Changed 4 years ago by igloo

  • difficulty set to Unknown
  • milestone set to Not GHC

Changed 3 years ago by guest

amended version; functor, name change, and more laconic documentation

Changed 3 years ago by guest

  • failure set to None/Unknown

I've attached a new patch, one using the 'void' name and Functor type signature.

(I wondered about the section to put it in, but then I realized 'forever' wasn't in the Prelude either, so 'void' would be as happy there.)

Changed 3 years ago by guest

My final headcount of the very long discussion is here:  http://www.haskell.org/pipermail/libraries/2010-January/012972.html

I think it's clear that there's overwhelming support for adding void/ignore, with minor quibbling over the exact name & type signature. void :: f a -> f () is the best compromise, I think, and I hope now that Don's point about 'void' has been addressed, igloo or someone could add it to base.

Changed 3 years ago by guest

What needs to be done to get this applied? Since the patch/email/ticket flurry 4 days, there haven't even been any objections. Is there someone I need to specifically email or chat with in #haskell?

--gwern

Changed 3 years ago by malcolm.wallace@…

  • version changed from 6.10.2 to 6.12.1
  • type changed from proposal to merge

Patch applied. Should it be merged to the ghc-6.12.x branch?

Changed 3 years ago by guest

Malcolm: I don't see any reason why it shouldn't be, do you?

(I suppose this would involve issues of base's version-number, but I don't know anything about that.)

Changed 3 years ago by ross

  • status changed from new to closed
  • type changed from merge to proposal
  • version changed from 6.12.1 to 6.13
  • resolution set to fixed

We don't change the API of core packages during the cycle.

Note: See TracTickets for help on using tickets.