oriaj
oriaj

Reputation: 788

CurrentTime to Day in Haskell

I'm try to make a helper funcion that give the date in Day format, so I have the following code

localDay :: Day
localDay = do 
  now <- liftIO $ getCurrentTime
  utctDay now

But get the following error

Couldn't match type ‘m0 b0’ with ‘Day’
Expected type: m0 UTCTime -> (UTCTime -> m0 b0) -> Day
  Actual type: m0 UTCTime -> (UTCTime -> m0 b0) -> m0 b0
In a stmt of a 'do' block: now <- liftIO $ getCurrentTime
In the expression:
  do { now <- liftIO $ getCurrentTime;
       utctDay now }
In an equation for ‘localDay’:
    localDay
      = do { now <- liftIO $ getCurrentTime;
             utctDay now }

Really I can't understant the reason of the error in this case because now should be of Type UTCTimẹ

Upvotes: 0

Views: 425

Answers (1)

chepner
chepner

Reputation: 530793

getCurrentTime :: IO UTCTime, so you can't simply return a Day value; you can only return an IO Day value (ignoring unsafePerformIO)

localDay :: IO Day
localDay = fmap utctDay getCurrentTime

Upvotes: 2

Related Questions