1. C. Dylan Shearer
  2. iotransaction

Source

iotransaction / undoable_test.hs

import Undoable
import System.Posix.Directory as Dir
import System.Posix.Files

makeDir2 :: UndoableIO ()
makeDir2 = do doAction $ createDirectory "dir2" 504
              addUndoer $ removeDirectory "dir2"

makeDir3 :: UndoableIO ()
makeDir3 = do exists <- doAction $ fileExist "dir2"
              if exists
                then do _makeDir3
                        makeDir4
                else return ()

_makeDir3 :: UndoableIO ()
_makeDir3 = do doAction $ createDirectory "dir2/dir3" 504
               addUndoer $ removeDirectory "dir2/dir3"

makeDir4 :: UndoableIO ()
makeDir4 = do doAction $ createDirectory "dir4" 504
              addUndoer $ removeDirectory "dir4"

main = execUndoable $ do makeDir2
                         makeDir3
                         undo