There is a much simpler way to do this and you can see that in my xmonad config. Essentially the important lines are these ones:
-- put it all together main = do nScreens <- countScreens -- just in case you are on a laptop like me count the screens so that you can go xmonad =<< xmobar myBaseConfig { modMask = myModMask
That xmonad there is provided by this line here:
import XMonad.Hooks.DynamicLog (dynamicLogXinerama, xmobar)
You can see the documentation for the xmobar function here.
And using that you should be able to do this for yourself! Cheers. You may also be able to pick up some other tips from my XMonad config so I would suggest that you have a browse.