I'm creating a simple language for interactive date wrangling. I want to have a rule that stands for "today":
import Data.Time
import qualified Text.Parsec as Parsec
import Text.Parsec.String(Parser)
data Date = Date { year :: Int
, month :: Int
, day :: Int
}
parseToday :: Parser Date
parseToday = do
Parsec.string "today"
now <- getCurrentTime
let (year, month, day) = toGregorian $ utctDay now
return $ Date year month day
This doesn't work because getCurrentTime returns a monad of type IO UTCTime while the Parser is of type Parser Date.
Certainly, getting the current time needs to be an IO action.
However, is there no remedy against putting everything in the IO monad, for all the other Parsers that I have?