gpt4 book ai didi

haskell - Haskell 中未导入记录的类型类实例

转载 作者:行者123 更新时间:2023-12-02 12:29:08 26 4
gpt4 key购买 nike

我正在尝试使用 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’

我想不通。我缺少导入步骤吗?我搜索了显式导入类型类实例的方法,但一无所获。

编辑:这是我的 session :

λ> 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’
λ>

最佳答案

通常这意味着您在范围内有相同类型的两个不同版本。例如。你有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 修复它

关于haskell - Haskell 中未导入记录的类型类实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50745505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com