darcs patch: Main.hs: get rid off non-standard patter... (and 4 more)

Tue Jun 19 00:25:30 CEST 2007 joachim.fasting@gmail.com * Main.hs: get rid off non-standard pattern guards. Use nested case statements when creating the winset binding. Looks _really_ ugly, compared to the original, and adds 3 loc. Tue Jun 19 05:43:42 CEST 2007 joachim.fasting@gmail.com * Xmonad.whenX: flip instead of lambda abstraction. Wed Jun 20 17:35:41 CEST 2007 joachim.fasting@gmail.com * Operations.hs: redundant parens. Wed Jun 20 18:59:51 CEST 2007 joachim.fasting@gmail.com * Remove use of ';' to circumvent layout rules. This adds about 3 loc, but using ';' is cheating anyways. Wed Jun 20 19:08:33 CEST 2007 joachim.fasting@gmail.com * XMonad.hs: minor cosmetic code tweaks.

On Wed, Jun 20, 2007 at 07:29:46PM +0200, joachim.fasting@gmail.com wrote:
[Main.hs: get rid off non-standard pattern guards. joachim.fasting@gmail.com**20070618222530 Use nested case statements when creating the winset binding. Looks _really_ ugly, compared to the original, and adds 3 loc. ] { hunk ./Main.hs 53 - let winset | ("--resume" : s : _) <- args - , [(x, "")] <- reads s = x - | otherwise = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + let defaultWinset = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + winset = case args of + ("--resume" : s : _) -> case reads s of + [(x, [])] -> x + _ -> defaultWinset + _ -> defaultWinset
This could be prettier with let winset = maybe (new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc)) id $ do ("--resume" : s : _) <- args [(x, "")] <- reads s return x which I think is closer to what the pattern guards desugar to.
[Remove use of ';' to circumvent layout rules. joachim.fasting@gmail.com**20070620165951 This adds about 3 loc, but using ';' is cheating anyways. ] { hunk ./Main.hs 60 - safeLayouts = case defaultLayouts of [] -> (full, []); (x:xs) -> (x,xs) + safeLayouts = case defaultLayouts of + [] -> (full, []) + (x:xs) -> (x,xs)
It's a question of style preference, but I consider safeLayouts = case defaultLayouts of [] -> (full, []) (x:xs) -> (x,xs) to be more readable. In isolation it's equally readable, but it allows me to see more code on the screen simultaneously. -- David Roundy Department of Physics Oregon State University

On Wednesday 20 June 2007 19:39:17 David Roundy wrote:
On Wed, Jun 20, 2007 at 07:29:46PM +0200, joachim.fasting@gmail.com wrote:
[Main.hs: get rid off non-standard pattern guards. joachim.fasting@gmail.com**20070618222530 Use nested case statements when creating the winset binding. Looks _really_ ugly, compared to the original, and adds 3 loc. ] { hunk ./Main.hs 53 - let winset | ("--resume" : s : _) <- args - , [(x, "")] <- reads s = x - | otherwise = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + let defaultWinset = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + winset = case args of + ("--resume" : s : _) -> case reads s of + [(x, [])] -> x + _ -> defaultWinset + _ -> defaultWinset
This could be prettier with
let winset = maybe (new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc)) id $ do ("--resume" : s : _) <- args [(x, "")] <- reads s return x
which I think is closer to what the pattern guards desugar to.
Your solution is way better than mine. Please pretend like I never sent this patch.

On Wed, Jun 20, 2007 at 07:45:25PM +0200, Joachim Fasting wrote:
On Wednesday 20 June 2007 19:39:17 David Roundy wrote:
On Wed, Jun 20, 2007 at 07:29:46PM +0200, joachim.fasting@gmail.com wrote:
[Main.hs: get rid off non-standard pattern guards. joachim.fasting@gmail.com**20070618222530 Use nested case statements when creating the winset binding. Looks _really_ ugly, compared to the original, and adds 3 loc. ] { hunk ./Main.hs 53 - let winset | ("--resume" : s : _) <- args - , [(x, "")] <- reads s = x - | otherwise = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + let defaultWinset = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + winset = case args of + ("--resume" : s : _) -> case reads s of + [(x, [])] -> x + _ -> defaultWinset + _ -> defaultWinset
This could be prettier with
let winset = maybe (new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc)) id $ do ("--resume" : s : _) <- args [(x, "")] <- reads s return x
which I think is closer to what the pattern guards desugar to.
Your solution is way better than mine. Please pretend like I never sent this patch.
Or you could resubmit with my solution... I'm at work, and while I can't resist suggesting prettier code, I also have set a hard rule about not procrastinating by working on xmonad during the day. -- David Roundy Department of Physics Oregon State University

On Wednesday 20 June 2007 20:02:45 David Roundy wrote:
On Wed, Jun 20, 2007 at 07:45:25PM +0200, Joachim Fasting wrote:
On Wednesday 20 June 2007 19:39:17 David Roundy wrote:
On Wed, Jun 20, 2007 at 07:29:46PM +0200, joachim.fasting@gmail.com wrote:
[Main.hs: get rid off non-standard pattern guards. joachim.fasting@gmail.com**20070618222530 Use nested case statements when creating the winset binding. Looks _really_ ugly, compared to the original, and adds 3 loc. ] { hunk ./Main.hs 53 - let winset | ("--resume" : s : _) <- args - , [(x, "")] <- reads s = x - | otherwise = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + let defaultWinset = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + winset = case args of + ("--resume" : s : _) -> case reads s of + [(x, [])] -> x + _ -> defaultWinset + _ -> defaultWinset
This could be prettier with
let winset = maybe (new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc)) id $ do ("--resume" : s : _) <- args [(x, "")] <- reads s return x
which I think is closer to what the pattern guards desugar to.
Your solution is way better than mine. Please pretend like I never sent this patch.
Or you could resubmit with my solution... I'm at work, and while I can't resist suggesting prettier code, I also have set a hard rule about not procrastinating by working on xmonad during the day. I would resend using your nice suggestion, but it won't type-check for me.

On Wed, Jun 20, 2007 at 11:41:25PM +0200, Joachim Fasting wrote:
This could be prettier with
let winset = maybe (new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc)) id $ do ("--resume" : s : _) <- args [(x, "")] <- reads s return x
which I think is closer to what the pattern guards desugar to.
Your solution is way better than mine. Please pretend like I never sent this patch.
Or you could resubmit with my solution... I'm at work, and while I can't resist suggesting prettier code, I also have set a hard rule about not procrastinating by working on xmonad during the day.
I would resend using your nice suggestion, but it won't type-check for me.
Ah, I left out the returns:
let winset = maybe (new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc)) id $ do ("--resume" : s : _) <- return $ args [(x, "")] <- return $ reads s return x -- David Roundy Department of Physics Oregon State University

On Wed, Jun 20, 2007 at 11:41:25PM +0200, Joachim Fasting wrote:
This could be prettier with
let winset = maybe (new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc)) id $ do ("--resume" : s : _) <- args [(x, "")] <- reads s return x
which I think is closer to what the pattern guards desugar to.
Your solution is way better than mine. Please pretend like I never sent this patch.
Or you could resubmit with my solution... I'm at work, and while I can't resist suggesting prettier code, I also have set a hard rule about not procrastinating by working on xmonad during the day.
I would resend using your nice suggestion, but it won't type-check for me.
Ah, I left out the returns:
let winset = maybe (new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc)) id $ do ("--resume" : s : _) <- return $ args [(x, "")] <- return $ reads s return x Of course, daft of me not to catch that. Nevertheless, it was fun trying to
On Thursday 21 June 2007 00:44:11 David Roundy wrote: try doing this the hard way (even learnt something today).

joachim.fasting:
Tue Jun 19 00:25:30 CEST 2007 joachim.fasting@gmail.com * Main.hs: get rid off non-standard pattern guards. Use nested case statements when creating the winset binding. Looks _really_ ugly, compared to the original, and adds 3 loc.
Tue Jun 19 05:43:42 CEST 2007 joachim.fasting@gmail.com * Xmonad.whenX: flip instead of lambda abstraction.
Wed Jun 20 17:35:41 CEST 2007 joachim.fasting@gmail.com * Operations.hs: redundant parens.
Wed Jun 20 18:59:51 CEST 2007 joachim.fasting@gmail.com * Remove use of ';' to circumvent layout rules. This adds about 3 loc, but using ';' is cheating anyways.
Wed Jun 20 19:08:33 CEST 2007 joachim.fasting@gmail.com * XMonad.hs: minor cosmetic code tweaks.
Content-Description: A darcs patch for your repository!
New patches:
[Main.hs: get rid off non-standard pattern guards. joachim.fasting@gmail.com**20070618222530 Use nested case statements when creating the winset binding. Looks _really_ ugly, compared to the original, and adds 3 loc. ] { hunk ./Main.hs 53 - let winset | ("--resume" : s : _) <- args - , [(x, "")] <- reads s = x - | otherwise = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + let defaultWinset = new [0..fromIntegral workspaces-1] (fromIntegral $ length xinesc) + winset = case args of + ("--resume" : s : _) -> case reads s of + [(x, [])] -> x + _ -> defaultWinset + _ -> defaultWinset }
Explained why we'll not apply this in previous mail.
[Xmonad.whenX: flip instead of lambda abstraction. joachim.fasting@gmail.com**20070619034342] { hunk ./XMonad.hs 195 -whenX a f = a >>= \b -> when b f +whenX a f = a >>= flip when f }
Well, maybe.
[Operations.hs: redundant parens. joachim.fasting@gmail.com**20070620153541] { hunk ./Operations.hs 102 - let n = fromIntegral $ W.screen (W.current ws) + let n = fromIntegral . W.screen $ W.current ws
Ok. good.
hunk ./Operations.hs 146 - let n = W.tag (W.workspace w) + let n = W.tag $ W.workspace w }
Rule of thumb is to use () for single application. Its not a crucial issue though.
[Remove use of ';' to circumvent layout rules. joachim.fasting@gmail.com**20070620165951 This adds about 3 loc, but using ';' is cheating anyways. ] { hunk ./Main.hs 60 - safeLayouts = case defaultLayouts of [] -> (full, []); (x:xs) -> (x,xs) + safeLayouts = case defaultLayouts of + [] -> (full, []) + (x:xs) -> (x,xs) hunk ./Operations.hs 115 - wmdelt <- atom_WM_DELETE_WINDOW ; wmprot <- atom_WM_PROTOCOLS - + wmdelt <- atom_WM_DELETE_WINDOW + wmprot <- atom_WM_PROTOCOLS }
No big reason to change these.
[XMonad.hs: minor cosmetic code tweaks. joachim.fasting@gmail.com**20070620170833] { hunk ./XMonad.hs 86 - \e -> (do hPutStrLn stderr (show e); runStateT (runReaderT errcase c) st)) + \e -> hPutStrLn stderr (show e) >> runStateT (runReaderT errcase c) st)
I prefer do notation here.
hunk ./XMonad.hs 164 -catchIO f = liftIO (f `catch` \e -> do hPutStrLn stderr (show e); hFlush stderr) +catchIO f = liftIO (f `catch` \e -> hPutStrLn stderr (show e) >> hFlush stderr)
; seems fine.
hunk ./XMonad.hs 185 - prog <- maybe (io $ getProgName) return mprog + prog <- maybe (io getProgName) return mprog
Better, thanks.
hunk ./XMonad.hs 207 -trace msg = io $! do hPutStrLn stderr msg; hFlush stderr +trace msg = io $! (hPutStrLn stderr msg >> hFlush stderr)
The use of >> complicates this.
participants (4)
-
David Roundy
-
dons@cse.unsw.edu.au
-
Joachim Fasting
-
joachim.fasting@gmail.com