-getGhcLoc ("-f" : ghc : args) = (Just ghc, args)
-getGhcLoc (('-' : 'f' : ghc) : args) = (Just ghc, args)
--- If you need the first GHC flag to be a -f flag then you can pass --
--- first
-getGhcLoc ("--" : args) = (Nothing, args)
-getGhcLoc args = (Nothing, args)
+getGhcLoc args = case args of
+ "-f" : ghc : args' -> f ghc args'
+ ('-' : 'f' : ghc) : args' -> f ghc args'
+ -- If you need the first GHC flag to be a -f flag then
+ -- you can pass -- first
+ "--" : args -> (Nothing, args)
+ args -> (Nothing, args)
+ where f ghc args' = -- If there is another -f flag later on then
+ -- that overrules the one that we've already
+ -- found
+ case getGhcLoc args' of
+ (Nothing, _) -> (Just ghc, args')
+ success -> success