fileExists :: Exp FilePath -> Exp Bool
fileExists x = do
    v <- mutable_ false
    Value x <- x
    yes <- newLabel
    end <- newLabel
    emit $ IfFileExists x yes end
    label yes
    v @= true
    label end
    v


-- | Performs a search for filespec, running the action with each file found.
--   If no files are found the error flag is set. Note that the filename output is without path.
--
-- > findEach "$INSTDIR/*.txt" $ \x ->
-- >     detailPrint x
--
--   If you jump from inside the loop to after the loop then you may leak a search handle.
fileExists :: Exp FilePath -> Exp Bool
fileExists x = do
    v <- mutable_ false
    Value x <- x
    yes <- newLabel
    end <- newLabel
    emit $ IfFileExists x yes end
    label yes
    v @= true
    label end
    v


-- | Performs a search for filespec, running the action with each file found.
--   If no files are found the error flag is set. Note that the filename output is without path.
--
-- > findEach "$INSTDIR/*.txt" $ \x ->
-- >     detailPrint x
--
--   If you jump from inside the loop to after the loop then you may leak a search handle.
fileExists x = do
    v <- mutable_ false
    Value x <- x
    yes <- newLabel
    end <- newLabel
    emit $ IfFileExists x yes end
    label yes
    v @= true
    label end
    v


-- | Performs a search for filespec, running the action with each file found.
--   If no files are found the error flag is set. Note that the filename output is without path.
--
-- > findEach "$INSTDIR/*.txt" $ \x ->
-- >     detailPrint x
--
--   If you jump from inside the loop to after the loop then you may leak a search handle.