Opened 5 years ago

Last modified 21 months ago

#7285 new feature request

mkWeakMVar is non-compositional

Reported by: edsko Owned by:
Priority: normal Milestone:
Component: Core Libraries Version: 7.6.1
Keywords: Cc: tkn.akio@…, idhameed@…, simonmar, core-libraries-committee@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In base 4.6 addMVarFinalizer is deprecated in favour of mkWeakMVar of type

    mkWeakMVar :: MVar a -> IO () -> IO (Weak (MVar a))

This type makes it inherently non-compositional. For instance, if we have a larger datatype T that contains an MVar somewhere inside then there in no way to define mkWeakT in terms of mkWeakMVar; instead, mkWeakT would have to be defined along the lines of

    mkWeakT :: T a -> IO () -> IO (Weak (T a))
    mkWeakT m@(MkT (MVar m#) _) f = IO $ \s ->
      case mkWeak# m# m f s of (# s1, w #) -> (# s1, Weak w #)

It would be better if the type of mkWeakMVar would change to

    mkWeakMVar :: MVar a -> v -> Maybe (IO ()) -> IO (Weak v)

(i.e., following mkWeak rather than mkWeakPtr).

(The same comment goes for related functions such as mkWeakIORef.)

Change History (12)

comment:1 Changed 5 years ago by akio

Cc: tkn.akio@… added

comment:2 Changed 5 years ago by igloo

difficulty: Unknown
Milestone: 7.8.1

comment:3 Changed 5 years ago by ihameed

Cc: idhameed@… added

comment:4 Changed 4 years ago by simonmar

Cc: simonmar added

comment:5 Changed 3 years ago by thoughtpolice


Moving to 7.10.1

comment:6 Changed 3 years ago by thomie

Cc: core-libraries-committee@… added
Component: CompilerCore Libraries
Owner: set to ekmett

comment:7 Changed 3 years ago by ekmett

I've sent out a proposal for discussion on libraries@ to seek community feedback, so we can finally clear this out. In general I'm in favor of making the change, though.

comment:8 Changed 3 years ago by thoughtpolice


Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:10 Changed 2 years ago by thoughtpolice


Milestone renamed

comment:11 Changed 2 years ago by thomie

Owner: ekmett deleted

comment:12 Changed 21 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.