parseOpt :: [OptDescr (Options -> Options)]
         -> [String] -> IO (Options, [String])
parseOpt options args = do
  progName <- getProgName

  case getOpt Permute options args of
    (o, n, [])   -> return (foldl (flip id) defaults o, n)
    (_, _, errs) ->
        ioError (userError (concat errs ++
                                   usageInfo (header progName) options))
    where header :: String -> String
          header name = "Usage: " ++ name ++ " " ++
                                   head args ++ " [OPTIONS...]"
parseOpt :: [OptDescr (Options -> Options)]
         -> [String] -> IO (Options, [String])
parseOpt options args = do
  progName <- getProgName

  case getOpt Permute options args of
    (o, n, [])   -> return (foldl (flip id) defaults o, n)
    (_, _, errs) ->
        ioError (userError (concat errs ++
                                   usageInfo (header progName) options))
    where header :: String -> String
          header name = "Usage: " ++ name ++ " " ++
                                   head args ++ " [OPTIONS...]"
parseOpt options args = do
  progName <- getProgName

  case getOpt Permute options args of
    (o, n, [])   -> return (foldl (flip id) defaults o, n)
    (_, _, errs) ->
        ioError (userError (concat errs ++
                                   usageInfo (header progName) options))
    where header :: String -> String
          header name = "Usage: " ++ name ++ " " ++
                                   head args ++ " [OPTIONS...]"