diff --git a/factorial/factorial.cabal b/factorial/factorial.cabal index ce95ebe..ed8258e 100644 --- a/factorial/factorial.cabal +++ b/factorial/factorial.cabal @@ -17,9 +17,10 @@ executable factorial -- other-modules: -- other-extensions: ghc-options: -threaded - build-depends: base >=4.6 && <4.9, - stm >=2.4 && <2.5, - hsqml >=0.3 && <0.4, - text >=1.2 && <1.3 + build-depends: base >=4.6 && <4.9, + monad-extras >=0.5 && <0.6, + stm >=2.4 && <2.5, + text >=1.2 && <1.3, + hsqml >=0.3 && <0.4 -- hs-source-dirs: default-language: Haskell2010 diff --git a/factorial/factorial.hs b/factorial/factorial.hs index fe26983..dd779ff 100644 --- a/factorial/factorial.hs +++ b/factorial/factorial.hs @@ -6,6 +6,7 @@ import Control.Concurrent (forkIO, killThread, myThreadId) import Control.Concurrent.STM import Control.Exception (evaluate, mask_) import Control.Monad +import Control.Monad.Extra (om) import Data.IORef import Data.Maybe import Data.Text (Text) @@ -13,11 +14,6 @@ import Graphics.QML import qualified Data.Text as T --- How are these not in Control.Monad? -whenM, unlessM :: Monad m => m Bool -> m () -> m () -whenM mcond mtrue = mcond >>= flip when mtrue -unlessM mcond mfalse = mcond >>= flip unless mfalse - main :: IO () main = do state <- newIORef $ T.pack "" @@ -38,7 +34,7 @@ main = do evaluate out writeIORef state out mask_ $ fireSignal skey obj - atomically $ whenM ((== Just tid) <$> readTMVar tidVar) $ + atomically $ om when ((== Just tid) <$> readTMVar tidVar) $ void $ swapTMVar tidVar Nothing ]