Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Trial where
- import System.IO
- import System.Directory
- import System.Time
- fileExists :: FilePath -> IO Bool
- fileExists name = do
- fileExists <- doesFileExist name
- if fileExists
- then return True
- else doesDirectoryExist name
- readDay :: String -> Int
- readDay = read . head . lines
- readOrCreate :: FilePath -> String -> IO String
- readOrCreate fp def = do
- exists <- fileExists fp
- if exists
- then readFile fp
- else writeFile fp def >> return def
- class TrialMechanism a where
- daysRemaining :: Int -> a -> IO Int
- updateDaysRemaining :: a -> Int -> IO ()
- instance TrialMechanism FilePath where
- daysRemaining def fp = fmap readDay (readOrCreate fp $ show def)
- updateDaysRemaining fp newDays = writeFile fp $ show newDays
Add Comment
Please, Sign In to add comment