Opened 4 years ago

Last modified 19 months ago

#12073 new feature request

Missing instance of MonadFix for Q

Reported by: jophish Owned by:
Priority: normal Milestone:
Component: Template Haskell Version:
Keywords: Cc: erikd
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Q is capable of being an instance of MonadFix. The definition of mfix is the same as fixIO except that the MVar handling is wrapped in runIO.

instance MonadFix Q where
  mfix k = do
    m <- runIO newEmptyMVar
    ans <- runIO (unsafeInterleaveIO (takeMVar m))
    result <- k ans
    runIO (putMVar m result)
    pure result

Change History (4)

comment:1 Changed 3 years ago by goldfire

I have no knowledge of whether this implementation is correct, although it certainly looks plausible. As the TH czar, I'm happy to accept this instance from a design point of view.

comment:2 Changed 3 years ago by ekmett

This looks reasonable to me. It acts like IO. I suppose any manually constructed infinite terms it might allow are entirely on the user's head anyways.

comment:3 Changed 3 years ago by erikd

Cc: erikd added

comment:4 Changed 19 months ago by dfeuer

One change: unsafeInterleaveIO is now safer than necessary, and this should instead use unsafeDupableInterleaveIO.

Note: See TracTickets for help on using tickets.