IO モナドにハマってますヽ(  ̄д ̄;)ノ

#!runghc

import System.Directory
import System.Time
import Data.Maybe
import Text.Regex

data Entry = Entry {
    path      :: FilePath,
    title     :: IO String,
    timestamp :: IO ClockTime,
    body      :: IO [String]
}

isMatch :: FilePath -> Bool
isMatch path = isJust $ matchRegex reg path where reg = mkRegex ".txt$"

consEntries :: FilePath -> Entry
consEntries fp = Entry {
    path      = fp,
    title     = titl,
    timestamp = time,
    body      = body
} where time = do t <- getModificationTime fp
                  return t
        fcon = do b <- readFile fp
                  return $ splitAt 1 $ splitRegex (mkRegex "\r?\n") b
        titl = do t <- fcon
                  return $ head $ fst $ t
        body = do b <- fcon
                  return $ snd $ b

getMatchedEntries :: IO [Entry]
getMatchedEntries = do list <- getDirectoryContents "data"
                       return $ map consEntries $ filter isMatch $ list

main = do list <- getMatchedEntries
          putStr $ unlines $ map (\e -> title e) $ list

これだと

blosxkel.hs:38:29:
    Couldn't match `String' against `IO String'
      Expected type: [String]
      Inferred type: [IO String]
    In the expression: (map (\ e -> title e)) $ list
    In the second argument of `($)', namely `(map (\ e -> title e)) $ list'

ってでちゃうんですよね (*>_<*)

data の中の IO をもう一回 bind しないといけないのかなぁ??? むずかしい…… 書きかたがわからない (笑)