controlIO from MonadLiftIO

1
2
3
4
5
6
7
8
9
10
11
12
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

import Control.Monad
import Control.Monad.IO.Unlift
import System.Console.Haskeline.MonadException

unliftToRunIO :: (Monad m) => UnliftIO m -> RunIO m
unliftToRunIO (UnliftIO f) = RunIO (fmap return . f)

controlIO' :: forall m a. (MonadUnliftIO m) => (RunIO m -> IO (m a)) -> m a
controlIO' f = join (withUnliftIO (f . unliftToRunIO))