-- | Class instances for several types. module System.FileSystem.Instances ( -- * @Monoid@ instances -- ** @FileSystem@ -- | A 'FileSystem' is a 'Monoid' with respect -- to the 'FileSystem' appending, being the 'emptyFileSystem' -- the neutral element. -- * @Binary@ instances -- | 'Binary' instances given by this module: -- -- * 'ClockTime' (this type comes from the "System.Time" module) -- -- * 'FileData' (an internal type, you don't need to use it) -- -- * 'File' -- -- * 'FileSystem' -- ) where import Data.Monoid (Monoid (..)) import Control.Arrow (second) import Data.Binary (Binary (..) , Word8 , Get) import System.Time (ClockTime (..)) -- import System.FileSystem.Types import System.FileSystem.Operators -- Monoid instance instance Monoid FileSystem where mempty = emptyFileSystem mappend = curry $ uncurry (foldr (<<:)) . second dirCnt -- Binary instance instance Binary ClockTime where put (TOD s m) = do put (0 :: Word8) put s put m get = do t <- get :: Get Word8 case t of 0 -> do s <- get m <- get return (TOD s m) instance Binary FileData where put (FD cnt lmt) = do put (0 :: Word8) put cnt put lmt get = do t <- get :: Get Word8 case t of 0 -> do cnt <- get lmt <- get return (FD cnt lmt) instance Binary File where put (File fd fn) = do put (0 :: Word8) put fd put fn get = do t <- get :: Get Word8 case t of 0 -> do fd <- get fn <- get return (File fd fn) instance Binary FileSystem where put (Directory xs) = do put (0 :: Word8) put xs get = do t <- get :: Get Word8 case t of 0 -> do xs <- get return (Directory xs)