我尝试将IO元组的元组成员(日期)与普通元组进行比较。
d1 ->(Integer, Int, Int)
和d2 -> IO (Integer, Int, Int)
是否可以比较这两个元组? 我已经尝试过类似的事情:
import Data.Time.Clock
import Data.Time.Calendar
import Data.Time.LocalTime
-- helper functions for tuples
x_fst (x,_,_) = x
x_snd (_,x,_) = x
x_trd (_,_,x) = x
getDate :: IO (Integer, Int, Int)
getDate = do
now <- getCurrentTime
tiz <- getCurrentTimeZone
let zoneNow = utcToLocalTime tiz now
let date@(year, month, day) = toGeorgian $ localDay zoneNow
return $ date -- here I will return an IO tuple -> IO (Integer, Int, Int)
compareDates :: a -> IO (Integer, Int, Int) -> IO Bool
compareDates d1 d2 = do
let year1 = x_fst d1
let year2 = x_fst d2
let month1 = x_snd d1
let month2 = x_snd d2
let day1 = x_trd d1
let day2 = x_trd d2
return $ (year1 == year2 && month1 == month2 && day1 == day2)
但是我收到一条消息,我无法将IO元组与普通元组进行比较:
Couldn't match expected type `(Integer, Integer, Integer)`
with actual type `IO (Integer, Int, Int)`
In the second argument of `compareDates`, namely `date`
有办法解决吗?我将不胜感激任何帮助。
谢谢。
答案 0 :(得分:1)
借助注释/聊天部分,我将其与以下代码一起使用:
sasl.jaas.config