controlIO from MonadLiftIO

Cale 2018-02-12 11:22:44.015338 UTC

1{-# LANGUAGE RankNTypes #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3
4import Control.Monad
5import Control.Monad.IO.Unlift
6import System.Console.Haskeline.MonadException
7
8unliftToRunIO :: (Monad m) => UnliftIO m -> RunIO m
9unliftToRunIO (UnliftIO f) = RunIO (\x -> fmap return (f x))
10
11controlIO' :: forall m a. (MonadUnliftIO m) => (RunIO m -> IO (m a)) -> m a
12controlIO' f = join (withUnliftIO (f . unliftToRunIO))