@@ -30,6 +30,7 @@ import Data.Maybe
3030import Data.Time.Clock.POSIX (getPOSIXTime)
3131import Data.Traversable (forM)
3232import Debug.Trace
33+import System.Directory
3334import System.IO
3435import System.IO.Error
3536import System.IO.Unsafe
@@ -387,6 +388,17 @@ execForeign env ctxt arity ty fn xs onfail
387388 "The argument to fileError should be a file handle, but it was " ++
388389 show handle ++
389390 ". Are all cases covered?"
391+ | Just (FFun "fileRemove" [(_,fileStr)] _) <- foreignFromTT arity ty fn xs
392+ = case fileStr of
393+ EConstant (Str f) -> do res <- execIO $ catch (do removeFile f
394+ return $ ioWrap $ EConstant $ I 0)
395+ (\e -> do writeIORef fileError $ mapError e
396+ return $ ioWrap $ EConstant $ I (-1))
397+ execApp env ctxt res (drop arity xs)
398+ _ -> execFail . Msg $
399+ "The argument to fileRemove should be a constant string, but it was " ++
400+ show fileStr ++
401+ ". Are all cases covered?"
390402 | Just (FFun "fileClose" [(_,handle)] _) <- foreignFromTT arity ty fn xs
391403 = case handle of
392404 EHandle h -> do execIO $ hClose h