summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Firth <locallycompact@gmail.com>2018-07-04 13:48:15 +0100
committerDaniel Firth <locallycompact@gmail.com>2018-07-09 15:42:16 +0100
commit46bfe0d20ee43ad90eade44a7ee22b0af1b7dd12 (patch)
treee35a8e4bdca3b38283e9cce52c606d60c1553a71
parent9ec36a6dd846d9f53f6bdb309012d5af70630a2d (diff)
Avoid using return (), use void and forM_
-rw-r--r--Bustle/Renderer.hs28
-rw-r--r--Bustle/StatisticsPane.hs5
-rw-r--r--Bustle/UI.hs13
-rw-r--r--Bustle/UI/Canvas.hs15
-rw-r--r--Bustle/UI/OpenTwoDialog.hs5
-rw-r--r--Bustle/Util.hs3
6 files changed, 28 insertions, 41 deletions
diff --git a/Bustle/Renderer.hs b/Bustle/Renderer.hs
index 36dd580..a962817 100644
--- a/Bustle/Renderer.hs
+++ b/Bustle/Renderer.hs
@@ -454,12 +454,10 @@ addUnique :: Bus -> UniqueName -> Renderer ApplicationInfo
addUnique bus n = do
let ai = ApplicationInfo NoColumn Set.empty Set.empty
existing <- getsApps (Map.lookup n) bus
- case existing of
- Nothing -> return ()
- Just _ -> warn $ concat [ "Unique name '"
- , unUniqueName n
- , "' apparently connected to the bus twice"
- ]
+ forM_ existing $ const $ warn $ concat [ "Unique name '"
+ , unUniqueName n
+ , "' apparently connected to the bus twice"
+ ]
modifyApps bus $ Map.insert n ai
return ai
@@ -691,16 +689,14 @@ processMessage bus dm@(Detailed _ m _ _) = do
where advance = advanceBy eventHeight -- FIXME: use some function of timestamp?
returnOrError f = do
call <- findCallCoordinates bus (inReplyTo m)
- case call of
- Nothing -> return ()
- Just (dm', (x,y)) -> do
- advance
- relativeTimestamp dm
- memberName dm' True
- f dm
- let duration = deTimestamp dm - deTimestamp dm'
- returnArc bus dm x y duration
- addMessageRegion dm
+ forM_ call $ \(dm', (x,y)) -> do
+ advance
+ relativeTimestamp dm
+ memberName dm' True
+ f dm
+ let duration = deTimestamp dm - deTimestamp dm'
+ returnArc bus dm x y duration
+ addMessageRegion dm
processNOC :: Bus
-> NOC
diff --git a/Bustle/StatisticsPane.hs b/Bustle/StatisticsPane.hs
index 3e4d3b5..b53335e 100644
--- a/Bustle/StatisticsPane.hs
+++ b/Bustle/StatisticsPane.hs
@@ -23,7 +23,7 @@ module Bustle.StatisticsPane
)
where
-import Control.Monad (forM_)
+import Control.Monad (forM_, void)
import Text.Printf
import Graphics.UI.Gtk
import Bustle.Missing (formatSize)
@@ -109,13 +109,12 @@ addStatColumn :: TreeView
-> String
-> (a -> Marquee)
-> IO ()
-addStatColumn view store title f = do
+addStatColumn view store title f = void $ do
col <- treeViewColumnNew
treeViewColumnSetTitle col title
renderer <- addTextRenderer col store True f
set renderer [ cellXAlign := 1 ]
treeViewAppendColumn view col
- return ()
addTextStatColumn :: TreeView
-> ListStore a
diff --git a/Bustle/UI.hs b/Bustle/UI.hs
index 44abafb..67583d6 100644
--- a/Bustle/UI.hs
+++ b/Bustle/UI.hs
@@ -23,6 +23,7 @@ module Bustle.UI
)
where
+import Control.Monad (void)
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Except
@@ -302,7 +303,7 @@ recorderRun wi target filename r = C.handle newFailed $ do
stopActivatedId <- wiStop wi `on` buttonActivated $ monitorStop monitor
handlerId <- monitor `on` monitorMessageLogged $ updateLabel
- _stoppedId <- monitor `on` monitorStopped $ \domain code message -> do
+ void $ monitor `on` monitorStopped $ \domain code message -> do
handleError domain code message
signalDisconnect stopActivatedId
@@ -314,8 +315,6 @@ recorderRun wi target filename r = C.handle newFailed $ do
hadOutput <- fmap (/= 0) (readIORef n)
finished hadOutput
-
- return ()
where
newFailed (GError domain code message) = do
finished False
@@ -391,7 +390,7 @@ finishedRecording wi tempFilePath producedOutput = do
spinnerStop (wiSpinner wi)
if producedOutput
- then do
+ then void $ do
-- TODO: There is a noticable lag when reloading big files. It would be
-- nice to either make the loading faster, or eliminate the reload.
loadLogWith (return wi) (RecordedLog tempFilePath)
@@ -401,7 +400,6 @@ finishedRecording wi tempFilePath producedOutput = do
io $ do
widgetSetSensitivity saveItem True
saveItem `on` buttonActivated $ showSaveDialog wi (return ())
- return ()
else do
setPage wi InstructionsPage
putInitialWindow wi
@@ -671,8 +669,7 @@ displayLog wi@WindowInfo { wiWindow = window
logDetails
sessionMessages
systemMessages
- rr = do
- io $ do
+ rr = io $ void $ do
wiSetLogDetails wi logDetails
hiddenRef <- newIORef Set.empty
@@ -708,8 +705,6 @@ displayLog wi@WindowInfo { wiWindow = window
updateDisplayedLog wi rr'
- return ()
-
showOpenDialog :: Window
-> B ()
showOpenDialog window = embedIO $ \r -> do
diff --git a/Bustle/UI/Canvas.hs b/Bustle/UI/Canvas.hs
index 51d69f4..0257753 100644
--- a/Bustle/UI/Canvas.hs
+++ b/Bustle/UI/Canvas.hs
@@ -32,7 +32,7 @@ where
import Data.Maybe (isNothing)
import Data.IORef
-import Control.Monad (forM_, when)
+import Control.Monad (forM_, when, void)
import Graphics.UI.Gtk
import Graphics.Rendering.Cairo (Render, translate)
@@ -92,7 +92,7 @@ incdec (+-) f adj = do
setupCanvas :: Eq a
=> Canvas a
-> IO ()
-setupCanvas canvas = do
+setupCanvas canvas = void $ do
let layout = canvasLayout canvas
-- Scrolling
@@ -133,7 +133,6 @@ setupCanvas canvas = do
_ -> stopEvent
layout `on` draw $ canvasDraw canvas
- return ()
canvasInvalidateArea :: Canvas a
-> Int
@@ -174,12 +173,10 @@ canvasClampAroundSelection canvas = do
when (isNothing id_) $ do
id' <- flip idleAdd priorityDefaultIdle $ do
rs <- readIORef $ canvasSelection canvas
- case rsCurrent rs of
- Nothing -> return ()
- Just (Stripe top bottom, _) -> do
- vadj <- layoutGetVAdjustment $ canvasLayout canvas
- let padding = (bottom - top) / 2
- adjustmentClampPage vadj (top - padding) (bottom + padding)
+ forM_ (rsCurrent rs) $ \(Stripe top bottom, _) -> do
+ vadj <- layoutGetVAdjustment $ canvasLayout canvas
+ let padding = (bottom - top) / 2
+ adjustmentClampPage vadj (top - padding) (bottom + padding)
writeIORef idRef Nothing
return False
diff --git a/Bustle/UI/OpenTwoDialog.hs b/Bustle/UI/OpenTwoDialog.hs
index afb2217..f9e1e44 100644
--- a/Bustle/UI/OpenTwoDialog.hs
+++ b/Bustle/UI/OpenTwoDialog.hs
@@ -23,7 +23,7 @@ module Bustle.UI.OpenTwoDialog
where
import Data.Maybe (isJust, isNothing, fromJust)
-import Control.Monad (when)
+import Control.Monad (when, void)
import Graphics.UI.Gtk
@@ -42,9 +42,8 @@ propagateCurrentFolder d1 d2 = d1 `on` currentFolderChanged $ do
f1 <- fileChooserGetCurrentFolder d1
f2 <- fileChooserGetCurrentFolder d2
otherFile <- fileChooserGetFilename d2
- when (isNothing otherFile && f1 /= f2 && isJust f1) $ do
+ when (isNothing otherFile && f1 /= f2 && isJust f1) $ void $
fileChooserSetCurrentFolder d2 (fromJust f1)
- return ()
setupOpenTwoDialog :: Window
-> (FilePath -> FilePath -> IO ())
diff --git a/Bustle/Util.hs b/Bustle/Util.hs
index 425f2aa..edb4c92 100644
--- a/Bustle/Util.hs
+++ b/Bustle/Util.hs
@@ -30,6 +30,7 @@ module Bustle.Util
where
import Control.Monad.Trans (MonadIO, liftIO)
+import Control.Monad
import Debug.Trace (trace)
import System.IO (hPutStrLn, stderr)
import Foreign.C.String
@@ -39,7 +40,7 @@ import Bustle.Translation (__)
-- Escape hatch to log a value from a non-IO monadic context.
traceM :: (Show a, Monad m) => a -> m ()
-traceM x = trace (show x) $ return ()
+traceM = void . return . trace . show
-- Log a warning which isn't worth showing to the user, but which might
-- interest someone debugging the application.