无法将类型“ time-1.8.0.2:Data.Time.Clock.Internal.UTCTime.UTCTime”与“ UTCTime”匹配

时间:2018-07-22 22:21:28

标签: haskell haskell-thyme

我不明白为什么我使用thyme库遇到此错误:

λ import qualified Data.Thyme.Format as ABC (formatTime)                                                                                          
λ import qualified Data.Thyme.Clock as XYZ                                        
λ import Data.Thyme.Time.Core (fromThyme)                                         
λ let test123 :: XYZ.UTCView -> String; test123 p = ABC.formatTime defaultTimeLocale "%Y-%m-%d" (fromThyme p :: XYZ.UTCTime)

<interactive>:4:96: error:
    • Couldn't match type ‘time-1.8.0.2:Data.Time.Clock.Internal.UTCTime.UTCTime’
                     with ‘XYZ.UTCTime’
      NB: ‘XYZ.UTCTime’
            is defined in ‘Data.Thyme.Clock.Internal’
                in package ‘thyme-0.3.5.5’
          ‘time-1.8.0.2:Data.Time.Clock.Internal.UTCTime.UTCTime’
            is defined in ‘Data.Time.Clock.Internal.UTCTime’
                in package ‘time-1.8.0.2’
        arising from a functional dependency between:
          constraint ‘Data.Thyme.Time.Core.Thyme XYZ.UTCTime XYZ.UTCView’
            arising from a use of ‘fromThyme’
          instance ‘Data.Thyme.Time.Core.Thyme
                      time-1.8.0.2:Data.Time.Clock.Internal.UTCTime.UTCTime XYZ.UTCView’
            at <no location info>
    • In the third argument of ‘formatTime’, namely
        ‘(fromThyme p :: XYZ.UTCTime)’
      In the expression:
        formatTime
          defaultTimeLocale "%Y-%m-%d" (fromThyme p :: XYZ.UTCTime)
      In an equation for ‘test123’:
          test123 p
            = formatTime
                defaultTimeLocale "%Y-%m-%d" (fromThyme p :: XYZ.UTCTime)

为什么引用time库中定义的UTCTime?

http://hackage.haskell.org/package/thyme-0.3.5.5/docs/Data-Thyme-Format.html#t:FormatTime

1 个答案:

答案 0 :(得分:1)

因为:

fromThyme :: Thyme b a => a -> b
instance Thyme Data.Time.Clock.UTCTime UTCView

您可能应该改用utcTime