Last active
November 21, 2019 15:29
-
-
Save syntheticsh/6ac39562e555d3427b9be05f65e7cc15 to your computer and use it in GitHub Desktop.
trying Monadic actions inside RIO
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 stack | |
| -- stack --resolver lts-14.2 script | |
| {-# LANGUAGE NoImplicitPrelude #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| module Main (main) where | |
| import RIO | |
| import Control.Monad.Trans.Maybe | |
| newtype App = App {appLogFunc :: LogFunc} | |
| instance HasLogFunc App where | |
| logFuncL = lens appLogFunc (\x y -> x { appLogFunc = y }) | |
| testJustIO :: MaybeT IO Int | |
| testJustIO = return 42 | |
| testJust :: Maybe Int | |
| testJust = return 42 | |
| main :: IO () | |
| main = do | |
| lo <- logOptionsHandle stderr False | |
| withLogFunc lo $ \lf -> | |
| let app = App {appLogFunc = lf} | |
| in runRIO app run2 | |
| run1 :: RIO App () | |
| run1 = do | |
| wut <- liftIO $ runMaybeT $ do | |
| something <- testJustIO | |
| somethingElse <- testJustIO | |
| return (something, somethingElse) | |
| case wut of | |
| Nothing -> logInfo "there was Nothing" | |
| Just (s1, s2) -> logInfo ("there is some numberThere " <> displayShow s1 <> " and " <> displayShow s2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment