module Reader where import Data Map as Map import Control Monad liftM

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Reader where
import Data.Map as Map
import Control.Monad (liftM)
import qualified Data.ByteString as S
import System.IO (withFile, IOMode(ReadMode), hGetContents)
data FeedState = FeedState { feedTitle :: String
, feedUrl :: S.ByteString
, readGuids :: Map.Map String Bool
} deriving (Show, Read)
feedState :: S.ByteString -> String -> FeedState
feedState url_ title_ = FeedState { feedTitle = title_, feedUrl = url_, readGuids = Map.empty}
data ReaderState = ReaderState { feeds :: [FeedState]
} deriving (Show, Read)
newState :: ReaderState
newState = ReaderState []
writeState :: FilePath -> ReaderState -> IO ()
writeState path state = writeFile path (show state)
readState :: FilePath -> IO ReaderState
readState path = withFile path ReadMode (\h -> do
contents <- hGetContents h
let ret = read contents
ret `seq` return ret
)
--(fmap read . hGetContents)