I prefer Devin's solution to mine but just for completeness here is an updated version of my method which works no matter how many master windows have been manually added or removed with mod-, or mod-. by resetting the layout (effectively setting the number of master windows to 1). Thanks to Brandon for pointing out some silliness I was doing.
data MasterPaneFlag = MasterPaneFlag { getFlag :: Bool }
deriving (Show, Typeable)
instance ExtensionClass MasterPaneFlag where
initialValue = MasterPaneFlag False
pickIncrFun :: Bool -> X ()
pickIncrFun flag = if flag then (sendMessage (IncMasterN (1))) else (sendMessage (IncMasterN 0))
toggleMasterPane :: X ()
toggleMasterPane = do
flag <- XS.get
XS.modify(MasterPaneFlag . not . getFlag)
asks config >>= \c -> setLayout (XMonad.layoutHook c) >> pickIncrFun (getFlag flag)