New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added toMessage
and doMessage
#320
base: master
Are you sure you want to change the base?
Conversation
With the PatternSynonyms extension, it's possible to do this even more nicely and transparently. Rather than exporting
Now you use |
I really like this idea 👍 I think we should go for that |
39ace87
to
7233d8c
Compare
Great, I like it better too! Also, a quick bikeshedding question: Which do you like better: |
src/XMonad/Core.hs
Outdated
|
||
-- | | ||
-- A wrapped value of some type in the 'Message' class. | ||
-- | ||
data SomeMessage = forall a. Message a => SomeMessage a | ||
data SomeMessage = forall a. Message a => AMessage a | ||
deriving (Typeable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GHC derives Typeable
automatically for every type now, so this is probably superfluous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good news.
...and derive (Typeable)
is now gone.
Well I do love me some bikeshedding :) My gut feeling was that |
With that in mind, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; I'll wait for someone else to look at this before merging, but I've no more complaints myself
`toMessage` wraps an instace of `MessageClass` in `SomeMessage`; this can be used in other functions to avoid excessive wrapping and re-wrapping. `doMessage` acts as `handleMessage` but with error "handling" (`userCodeDef`) and using `toMessage` to automatically wrap with `SomeMessage` when necessary (see XMonad.Layout for why that's nice.)
Using `AMessage` as the constructor makes it easier for Haddock to know that we want to link to the class rather than the constructor.
I also moved the definition of `doMessage` above `fromMessage` to avoid messing with the flow of class definitions.
At this point it seems safe to remove the `DeriveDataTypeable` language pragma as well, but I have not.
Looks like `where` indentation is usually 2 spaces xmonad.
599aa7a
to
6be48d6
Compare
I'll be much more comfortable merging this if the newly added function(s) had some actual usage somewhere. That way it's easier to gauge the benefits and possible problems. Also, I noticed that you fork has a lot of extra commits, some of which get submitted as PRs, sometimes. I wonder if that's just your experiments or if you eventually intend all of that to be upstreamed? Would you perhaps like to join the IRC channel so that we can coordinate efforts? |
Good point. I didn't want to touch existing code (yet...), but there are a number of places where I think it would be useful, both in xmonad and for folks writing extensions (one less thing to be confused by). For example, it would marginally simplify the message-handling code in XMonad.Operations.
It's totally experimental. Occasionally something seems useful, small, and clear enough that I split it out into a PR, but for the most part I'd be terrified of accidentally introducing a bug into the venerable xmonad codebase. |
On Thu, Sep 09 2021 09:08, wygulmage wrote:
For example, it would marginally simplify the message-handling code in
XMonad.Operations.
Depending on how big of an undertaking this is, I think doing that as a
"proof of concept" that this is a good change would be great!
|
Keep in mind that you can submit a PR with that change and mark it as a draft, so it won't be considered as an official PR. |
Description
toMessage
wraps an instance ofMessageClass
inSomeMessage
unless it's alreadySomeMessage
; this can beused in other functions to avoid excessive wrapping and re-wrapping.
doMessage
acts ashandleMessage
but with error "handling" (userCodeDef
)and using
toMessage
to automatically wrap withSomeMessage
whennecessary (see XMonad.Layout for why that's nice.)
I was wondering why
XMonad.Operations.sendMessageWithNoRefresh
was usingcatchX
while general use ofhandleMessage
could still throw on a poorly defined instance ofLayoutClass
. This puts the error "handling" (semi-ignoring) in as basic a function as possible and then use that as much as possible, rather thanhandleMessage
.XMonad.Layout defines an internal function
handle
to wrap withSomeMessage
before callinghandleMessage
.doMessage
as defined here can be used instead.Possible complications of this include making
SomeMessage
an instance ofMessage
(technically you could wrapSomeMessage
arbitrarily deep if you didn't usetoMessage
), and the larger API ofdoMessage
andhandleMessage
with identical signatures and equivalent function.This would also slightly simplify the code in #291 by moving the error handling out of
sendMessageWithNoRefresh
.Checklist
I've read CONTRIBUTING.md
I've confirmed these changes don't belong in xmonad-contrib instead
I tested my changes with xmonad-testing
I updated the
CHANGES.md
file