Skip to content

Instantly share code, notes, and snippets.

@Hogeyama
Last active October 6, 2024 13:37
Show Gist options
  • Select an option

  • Save Hogeyama/140d0d78c684d6757619ef04580ecdd7 to your computer and use it in GitHub Desktop.

Select an option

Save Hogeyama/140d0d78c684d6757619ef04580ecdd7 to your computer and use it in GitHub Desktop.
MonadUnliftIO (ExceptT e m)
-- [Control.Monad.IO.Unlift](https://hackage.haskell.org/package/unliftio-core-0.2.1.0/docs/Control-Monad-IO-Unlift.html#t:MonadUnliftIO)
-- 定義はできるがInverse lawが成り立たないのでダメ
-- withRunInIO (\_ -> throwIO e) === liftIO (throwIO e)
-- にならないといけないが、pure (Left e)になってしまう。
-- たぶんjoinの保存則も成り立たないんじゃないかな。
--
-- あと、askUnliftIOを使うとtryのスコープを抜けてしまって酷いバグになりそう。
-- askUnliftIO = withRunInIO (\run -> return (UnliftIO run))
instance (MonadUnliftIO m, Exception e) => MonadUnliftIO (ExceptT e m) where
withRunInIO inner =
ExceptT $
withRunInIO @m \unlift -> try $
inner \m ->
unlift (runExceptT m) >>= \case
Left e -> throwIO e
Right b -> pure b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment