@@ -30,6 +30,7 @@ import Data.Maybe
30import Data.Time.Clock.POSIX (getPOSIXTime)
30import Data.Time.Clock.POSIX (getPOSIXTime)
31import Data.Traversable (forM)
31import Data.Traversable (forM)
32import Debug.Trace
32import Debug.Trace
33+import System.Directory
33import System.IO
34import System.IO
34import System.IO.Error
35import System.IO.Error
35import System.IO.Unsafe
36import System.IO.Unsafe
@@ -387,6 +388,17 @@ execForeign env ctxt arity ty fn xs onfail
387 "The argument to fileError should be a file handle, but it was " ++
388 "The argument to fileError should be a file handle, but it was " ++
388 show handle ++
389 show handle ++
389 ". Are all cases covered?"
390 ". Are all cases covered?"
391+ | Just (FFun "fileRemove" [(_,fileStr)] _) <- foreignFromTT arity ty fn xs
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 " ++
401+ ". Are all cases covered?"
390 | Just (FFun "fileClose" [(_,handle)] _) <- foreignFromTT arity ty fn xs
402 | Just (FFun "fileClose" [(_,handle)] _) <- foreignFromTT arity ty fn xs
391 = case handle of
403 = case handle of
392 EHandle h -> do execIO $ hClose h
404 EHandle h -> do execIO $ hClose h