Ticket #4159 (closed proposal: fixed)

Opened 3 years ago

Last modified 3 years ago

move Monad and MonadFix instances for Either from mtl to base

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

Description

These patches move the Monad and MonadFix? instances for Either (currently in the mtl package) to Control.Monad.Instances and Control.Monad.Fix respectively (both in the base package). The Monad instance is still an orphan, to retain Haskell 98 compatibility, but the MonadFix? instance is together with its class. The Error constraint is removed from both instances, and the default definition of fail is used.

Discussion deadline: 20th July 2010

Attachments

mtl.patch Download (2.0 KB) - added by ross 3 years ago.
base.patch Download (35.5 KB) - added by ross 3 years ago.

Change History

Changed 3 years ago by ross

Changed 3 years ago by ross

Changed 3 years ago by ross

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

There was a lengthy discussion. Beyond the move, the change involves a classic trade-off: the Either monad instance becomes usable on arbitrary types, but the fail method becomes less useful; in particular, pattern match failure in this monad becomes an error.

More than a dozen people were in favour of the change. A popular argument was that Either is a general purpose type modelling categorical sum, so it should have the simple and familiar monad instance.

There were two arguments against, in different directions:

  • Claus Reinke wished to retain pattern match failure. We considered adding fail s = Left (error s) but this would please no-one: for the pattern matching use it would be equivalent to using the Maybe monad instead.
  • Iavor Diatchki opposed defining any instance of Monad Either, arguing that it promoted bad style. It was pointed out that because instances in Haskell are effectively global, most code already has the instance.
Note: See TracTickets for help on using tickets.