Search code examples
haskellarchlinuxxmonad

Haskell curly brace parse error


Running Manjaro and trying to get XMonad to work I encountered a parse error on input '{' with the following xmonad.hs:

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO

main = do
  xmproc <- spawnPipe "xmobar"

  xmonad $ defaultConfig
  { manageHook = manageDocks <+> manageHook defaultConfig
  , layoutHook = avoidStruts  $  layoutHook defaultConfig
  , logHook = dynamicLogWithPP xmobarPP
          { ppOutput = hPutStrLn xmproc
          , pptitle = xmobarColor "green" "" . shorten 50
          }
  , modMask = mod4Mask   -- rebind Mod to the windows key
  } `additionalKeys`
  [ ((mod4Mask .|. shiftMask, xK_z), spawn "xscreensaver-command -lock; xset dmps force off")
  , ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
  , ((0, xK_Print), spawn "scrot")
  ]

I have found this solution on su.sx and took my xmonad.hs from readthedocs.io. For getting started I would like to use that config file, I do not know however how to apply the solution to this. If somebody proficient could explain why that error appears and how to fix it, I'd really appreciate it since I just recently started with Haskell and it's really bending my mind to an unknown extent... :D


Solution

  • Indent everything after the xmonad $ defaultConfig line further to the right (it seems some of the indentation was lost when you pasted the example):

    main = do
        xmproc <- spawnPipe "xmobar"
    
        xmonad $ defaultConfig
            { manageHook = manageDocks <+> manageHook defaultConfig
            , layoutHook = avoidStruts  $  layoutHook defaultConfig
            , logHook = dynamicLogWithPP xmobarPP
                            { ppOutput = hPutStrLn xmproc
                            , ppTitle = xmobarColor "green" "" . shorten 50
                            }
            , modMask = mod4Mask     -- Rebind Mod to the Windows key
            } `additionalKeys`
            [ ((mod4Mask .|. shiftMask, xK_z), spawn "xscreensaver-command -lock; xset dpms force off")
            , ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
            , ((0, xK_Print), spawn "scrot")
            ]
    

    Lines at the "parent" indentation level in a do-block are parsed as separate statements, which is not appropriate here.