[Xmonad] xmonad-utils: small x apps for xmonad

Gwern Branwen gwern0 at gmail.com
Wed Aug 22 22:36:43 EDT 2007


On  0, Stefan O'Rear <stefanor at cox.net> scribbled:
> On Wed, Aug 22, 2007 at 12:09:21PM -0400, Gwern Branwen wrote:
> >      , ((modMask .|. shiftMask, xK_g     ), spawn $ "google" ++ unsafePerformIO(getSelection))
> >
> > But notice I used unsafePerformIO. The reason is that if you try to
> > simply concatenate "google" and getSelection, there's a type mismatch.
> > You can then try using liftM to do it, like ("google"++) `liftM`
> > getSelection, and that will work well. Unfortunately, spawn :: String
> > -> X (), so spawn needs to be lifted. (The internal /bin/sh stuff
> > apparently requires a String too, so it's not spawn's fault.) But if
> > you go 'spawn (("google"++) `liftM` getSelection' - which on its own
> > would work - the resulting type is something like IO ( X ()). And that
> > just can't be allowed inside 'keys'. At least, the only solution I
> > could find was to just slice the Gordian knot and avoid introducing
> > the IO signature in the first place. Monads may be the greatest thing
> > since sliced bread, but most of the time they're just a pain :(
>
> It's a lot easier if you use the 'io' function, type forall a. IO a -> X a  :
>
> spawn . ("google " ++) =<< io getSelection
>
> Stefan

And as usual the experts chime in with 'Oh, that's easy!' :)

Yes, that works well. I didn't realize it was possible to convert an X () to an IO () (which is what io is doing, if I understand correctly). Still don't quite understand the use of bind and composition, but it works, and obviates the need for xclip! Subjectively, it's also faster.

--
gwern
"genie" MEU/SOCPSAC Iraq NASA Bunny Amherst Egret Meade import Kvashnin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/xmonad/attachments/20070822/48294941/attachment.bin


More information about the Xmonad mailing list