我尝试使用time-recurrence库中的UTCTime实例CalendarTimeConvertible。它已在文档中列出,但当我将库导入ghci并评估i: CalendarTimeConvertible
时,实例不会出现。
class CalendarTimeConvertible t where
toCalendarTime :: t -> CalendarTime
fromCalendarTime :: CalendarTime -> Maybe t
-- Defined in ‘time-recurrence-0.9.3:Data.Time.CalendarTime.CalendarTime’
instance CalendarTimeConvertible CalendarTime
-- Defined in ‘time-recurrence-0.9.3:Data.Time.CalendarTime.CalendarTime’
它也不会显示在i: UTCTime
的输出中。
data UTCTime = UTCTime {utctDay :: Day, utctDayTime :: DiffTime}
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Eq UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Ord UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Read UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Format.Parse’
instance Show UTCTime
-- Defined in ‘time-1.9.1:Data.Time.LocalTime.Internal.ZonedTime’
instance ParseTime UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Format.Parse.Instances’
instance FormatTime UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Format.Format.Instances’
我无法弄明白。我是否缺少进口步骤?我搜索了显式导入类型类实例的方法,但是空了。
修改 这是我的会议:
λ> import Data.Time.Clock
λ> :i UTCTime
data UTCTime
= UTCTime {utctDay :: time-1.9.1:Data.Time.Calendar.Days.Day,
utctDayTime :: DiffTime}
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Eq UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Ord UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Read UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Format.Parse’
instance Show UTCTime
-- Defined in ‘time-1.9.1:Data.Time.LocalTime.Internal.ZonedTime’
λ> import Data.Time.CalendarTime
λ> :i CalendarTimeConvertible
class CalendarTimeConvertible t where
toCalendarTime :: t -> CalendarTime
fromCalendarTime :: CalendarTime -> Maybe t
-- Defined in ‘time-recurrence-0.9.3:Data.Time.CalendarTime.CalendarTime’
instance CalendarTimeConvertible CalendarTime
-- Defined in ‘time-recurrence-0.9.3:Data.Time.CalendarTime.CalendarTime’
λ> :i UTCTime
data UTCTime
= UTCTime {utctDay :: time-1.9.1:Data.Time.Calendar.Days.Day,
utctDayTime :: DiffTime}
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Eq UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Ord UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Clock.Internal.UTCTime’
instance Read UTCTime
-- Defined in ‘time-1.9.1:Data.Time.Format.Parse’
instance Show UTCTime
-- Defined in ‘time-1.9.1:Data.Time.LocalTime.Internal.ZonedTime’
λ>
答案 0 :(得分:4)
time-recurrence
取决于time < 1.6
,但您的会话使用time-1.9.1
。这意味着导入的time
包与time
正在使用的time-recurrence
不同,因此具有实例的UTCTime
类型不在范围内。
您需要以某种方式隐藏较新的time
或修复time-recurrence
以构建它。
答案 1 :(得分:4)
通常,这意味着您在范围内有两个相同类型的不同版本。例如。您从UTCTime
获得了time-1.9.1
,但time-recurrence
从UTCTime
定义了time-1.5.0.1
的实例。
要检查理论,请尝试运行ghc-pkg list time
。如果我是对的,它将列出安装的两个不同版本。
另请注意,time-recurrence
不支持time-1.9.1
。它对time
:
time >= 1.4 && < 1.6
这证实了我的理论。
您可以使用ghci -hide-package time-1.5.0.1