darcs patch: simplify StackSet.delete

Sun Jun 24 07:48:54 PDT 2007 David Roundy

droundy: > Sun Jun 24 07:48:54 PDT 2007 David Roundy> * simplify StackSet.delete > Content-Description: A darcs patch for your repository! > > New patches: > > [simplify StackSet.delete > David Roundy **20070624144854] > < > > { > hunk ./StackSet.hs 431 > -- * otherwise, delete doesn't affect the master. > -- > delete :: (Integral i, Ord a, Eq s) => a -> StackSet i a s -> StackSet i a s > -delete w s | Just w == peek s = remove s -- common case. > +delete w s | Just w == peek s = modify Nothing (filter (/= w)) s -- common case. > | otherwise = maybe s (removeWindow.tag.workspace.current $ s) (findIndex w s) > where > -- find and remove window script > hunk ./StackSet.hs 435 > - removeWindow o n = foldr ($) s [view o,remove,view n] > - > - -- actual removal logic, and focus/master logic: > - remove = modify Nothing $ \c -> > - if focus c == w > - then case c of > - Stack _ ls (r:rs) -> Just $ Stack r ls rs -- try down first > - Stack _ (l:ls) [] -> Just $ Stack l ls [] -- else up > - Stack _ [] [] -> Nothing > - else Just $ c { up = w `L.delete` up c, down = w `L.delete` down c } > + removeWindow o n = foldr ($) s [view o,modify Nothing (filter (/= w)),view n] How does this ensure the old semantics for where focus goes, is preserved? Does it rely on filter implementing the same focus semantics as 'remove' did? -- Don

dons:
droundy:
Sun Jun 24 07:48:54 PDT 2007 David Roundy
* simplify StackSet.delete
Ah I see, its part of a larger set of patches to allow sticky windows. This is a significant change in the core semantics --we'll need to talk it through. -- Don

On Mon, Jun 25, 2007 at 02:47:54PM +1000, Donald Bruce Stewart wrote:
dons:
droundy:
Sun Jun 24 07:48:54 PDT 2007 David Roundy
* simplify StackSet.delete Ah I see, its part of a larger set of patches to allow sticky windows. This is a significant change in the core semantics --we'll need to talk it through.
But it's still an improvement on its own (which is why I sent it separately): it simplifies the code without changing semantics, which is almost always a good thing. -- David Roundy Department of Physics Oregon State University

On Mon, Jun 25, 2007 at 02:43:03PM +1000, Donald Bruce Stewart wrote: > droundy: > > Sun Jun 24 07:48:54 PDT 2007 David Roundy> > * simplify StackSet.delete > > > > Content-Description: A darcs patch for your repository! > > > > New patches: > > > > [simplify StackSet.delete > > David Roundy **20070624144854] > > < > > > { > > hunk ./StackSet.hs 431 > > -- * otherwise, delete doesn't affect the master. > > -delete w s | Just w == peek s = remove s -- common case. > > +delete w s | Just w == peek s = modify Nothing (filter (/= w)) s -- common case. > > | otherwise = maybe s (removeWindow.tag.workspace.current $ s) (findIndex w s) > > where > > -- find and remove window script > > hunk ./StackSet.hs 435 > > - removeWindow o n = foldr ($) s [view o,remove,view n] > > - > > - -- actual removal logic, and focus/master logic: > > - remove = modify Nothing $ \c -> > > - if focus c == w > > - then case c of > > - Stack _ ls (r:rs) -> Just $ Stack r ls rs -- try down first > > - Stack _ (l:ls) [] -> Just $ Stack l ls [] -- else up > > - Stack _ [] [] -> Nothing > > - else Just $ c { up = w `L.delete` up c, down = w `L.delete` down c } > > + removeWindow o n = foldr ($) s [view o,modify Nothing (filter (/= w)),view n] > > How does this ensure the old semantics for where focus goes, is preserved? > Does it rely on filter implementing the same focus semantics as 'remove' did? Yes, that's what it relies on, which filter currently does. It seems better to enforce this in filter, so there'd be just one piece of code defining the desired semantics. -- David Roundy Department of Physics Oregon State University

droundy: > On Mon, Jun 25, 2007 at 02:43:03PM +1000, Donald Bruce Stewart wrote: > > droundy: > > > Sun Jun 24 07:48:54 PDT 2007 David Roundy> > > * simplify StackSet.delete > > > > > > > Content-Description: A darcs patch for your repository! > > > > > > New patches: > > > > > > [simplify StackSet.delete > > > David Roundy **20070624144854] > > > < > > > > { > > > hunk ./StackSet.hs 431 > > > -- * otherwise, delete doesn't affect the master. > > > -delete w s | Just w == peek s = remove s -- common case. > > > +delete w s | Just w == peek s = modify Nothing (filter (/= w)) s -- common case. > > > | otherwise = maybe s (removeWindow.tag.workspace.current $ s) (findIndex w s) > > > where > > > -- find and remove window script > > > hunk ./StackSet.hs 435 > > > - removeWindow o n = foldr ($) s [view o,remove,view n] > > > - > > > - -- actual removal logic, and focus/master logic: > > > - remove = modify Nothing $ \c -> > > > - if focus c == w > > > - then case c of > > > - Stack _ ls (r:rs) -> Just $ Stack r ls rs -- try down first > > > - Stack _ (l:ls) [] -> Just $ Stack l ls [] -- else up > > > - Stack _ [] [] -> Nothing > > > - else Just $ c { up = w `L.delete` up c, down = w `L.delete` down c } > > > + removeWindow o n = foldr ($) s [view o,modify Nothing (filter (/= w)),view n] > > > > How does this ensure the old semantics for where focus goes, is preserved? > > Does it rely on filter implementing the same focus semantics as 'remove' did? > > Yes, that's what it relies on, which filter currently does. It seems > better to enforce this in filter, so there'd be just one piece of code > defining the desired semantics. I like this idea, but this does actually change the focus semantics for the 'else up' case. Try deleting the last window in a stack. Focus will move to master, not 'up'. I will add a QC test to check the desired semantics, so changes like this would be caught. -- Don

On Tue, Jun 26, 2007 at 01:47:06PM +1000, Donald Bruce Stewart wrote:
Yes, that's what it relies on, which filter currently does. It seems better to enforce this in filter, so there'd be just one piece of code defining the desired semantics.
I like this idea, but this does actually change the focus semantics for the 'else up' case. Try deleting the last window in a stack. Focus will move to master, not 'up'. I will add a QC test to check the desired semantics, so changes like this would be caught.
Any reason not to give filter the desired semantics? I don't see how its single current use could be affected in a meaningful way. -- David Roundy http://www.darcs.net
participants (2)
-
David Roundy
-
dons@cse.unsw.edu.au