Today I ran into the following problem:
I can read the current screen resolution in Haskell using Xlib-bindings using a function called getScreenWidth (--> I get an IO Integer). This is working so far.
Now I want to use that value as a label for a plugin of my desktop environment (xmonad). The plugin infrastructure only allows a function mapping a "WorkspaceId" (which basically is an integer) to a String.
...
-- Constructor for PrettyPrint:
ppCurrent :: WorkspaceId -> String
...
Currently I am using my own function to map an ID to a String, which is working:
myPPCurrent :: WorkspaceId -> String
myPPCurrent x = "Desktop: " ++ show x
The output is as expected "Desktop: 1" (or whatever ID i am on).
Now I want it to be "Desktop: 1 (1680px)" where 1680 equals the return value of getScreenWidth.
My Problem: getScreenWidth returns IO Integer, so I can not simply use,
myPPCurrent x = do
y <- getScreenWidth
return "Desktop: " ++ show x ++ show y
since i the return type isn't String. Google told me, that I can not convert "IO Integer" to "Integer" in Haskell, so I really have no clue, how I can keep the prototype/constructor (however Haskell calls it) "WorkspaceId -> String" while using an "IO Integer" to generate that String.
Is that even possible at all? If so, how?