I’m having a bit of a problem with converting the output of these functions below to an Int
date :: IO (Integer,Int,Int)
date = getCurrentTime >>= return . toGregorian . utctDay
date' :: IO Integer
date' = getCurrentTime >>= return . toModifiedJulianDay . utctDay
Basically I want to take the output from either (not fussed which as long as it’s possible) and turn it into an int. e.g. Today is the 20/4/11 so date would give (2011,4,20) and date' would give 55671.
In an ideal world I want a couple of functions to flatten these IO functions to give an Int – (2011,4,20) to 2011420 and 55671 (currently of type IO Integer) to 55671 as an Int
Please advise me if there are better ways of completing this!
edit: Sorry if it wasnt clear, I meant how can you convert the output of date (2011,4,20) :: IO (Integer,Int,Int) to 20110420 :: Int
If I understood part of your question correctly, you basically want a function, say
f, such thatf (123,456,789) = 123456789, where all those numbers are numbers. Sof :: (Integer, Int, Int) -> Integer.In ghci:
edit: Please never forget, that basically, there is no (noncheating) function
IO a -> a. So what you want is impossible unless you break purity principles. Please consider just using the functionfmap f :: IO (Integer, Int, Int) -> IO Integer.