Created
January 12, 2015 18:18
-
-
Save andrewberls/ead42fc9ccfb29dd16d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Data.Maybe | |
import Text.Printf | |
import qualified Data.DateTime as DT | |
data Interval = Interval { start :: DT.DateTime | |
, end :: DT.DateTime } | |
deriving (Show) | |
-- TODO: this shouldn't exist | |
dayToInt :: DT.DateTime -> Int | |
dayToInt day = d where (y, m, d, _, _, _) = DT.toGregorian day | |
days :: Interval -> [DT.DateTime] | |
days inv = map (DT.fromGregorian' sy sm) range | |
where (sy, sm, sd, _, _, _) = DT.toGregorian (start inv) | |
ed = dayToInt (end inv) | |
range = [sd..ed] | |
intakeBase = "/Users/andrew/code/hsandbox/events" | |
buildFilename :: Int -> String | |
buildFilename d = printf (intakeBase ++ "/%d.json") d | |
filesForInterval :: Interval -> [String] | |
filesForInterval inv = map buildFilename dayNums | |
where dayNums = map dayToInt (days inv) | |
-- Main.hs:33:28: | |
-- Couldn't match type ‘IO’ with ‘Maybe’ | |
-- Expected type: Maybe String | |
-- Actual type: IO String | |
-- In a stmt of a 'do' block: content <- readFile f | |
-- In the expression: | |
-- do { content <- readFile f; | |
-- return $ Just (lines content) } | |
-- | |
-- Main.hs:34:17: | |
-- Couldn't match type ‘Maybe [String]’ with ‘[String]’ | |
-- Expected type: Maybe [String] | |
-- Actual type: Maybe (Maybe [String]) | |
-- In a stmt of a 'do' block: return $ Just (lines content) | |
-- In the expression: | |
-- do { content <- readFile f; | |
-- return $ Just (lines content) } | |
-- In an equation for ‘parseFile’: | |
-- parseFile f | |
-- = do { content <- readFile f; | |
-- return $ Just (lines content) } | |
-- Failed, modules loaded: none. | |
parseFile :: String -> Maybe [String] | |
parseFile f = do | |
content <- readFile f | |
return $ Just (lines content) | |
main :: IO () | |
main = do | |
let start = DT.fromGregorian' 2014 12 16 | |
end = DT.fromGregorian' 2014 12 20 | |
print $ filesForInterval $ Interval start end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment