Created
July 11, 2025 09:02
-
-
Save cideM/68f0be9aa4e6699a8f71d7ea81ae3490 to your computer and use it in GitHub Desktop.
UnliftIO Blog Post Nix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env nix-shell | |
| #! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz | |
| #! nix-shell -p "haskell.packages.ghc96.ghcWithPackages (pkgs: with pkgs; [unliftio])" ghcid | |
| #! nix-shell -i ghcid | |
| import Control.Monad.IO.Unlift | |
| import Control.Monad.Trans.Reader | |
| foo :: (String -> IO ()) -> IO () | |
| foo func = func "test" | |
| foo2 :: (String -> ReaderT String IO ()) | |
| -> ReaderT String IO () | |
| foo2 func = | |
| askUnliftIO >>= | |
| \u -> liftIO $ foo (unliftIO u . func) | |
| -- ^^^ note that we're still calling | |
| -- the original `foo`. We didn't have to | |
| -- reimplement anything | |
| -- Or alternatively and more concisely | |
| foo2' func = | |
| withRunInIO $ \runInIO -> foo (runInIO . func) | |
| main :: IO () | |
| main = print "HI" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment