它是`time-1.5'包中的一个隐藏模块。跑步时#34; :load Data.Time.Clock.UTC"

时间:2014-12-17 13:20:22

标签: haskell

我正在尝试BetterPredicate.hs的{​​{1}},关于ClockTime的代码段代码在我的ghc 7.6.3下引发错误:

    Couldn't match expected type `ClockTime'
            with actual type `time-1.4.0.1:Data.Time.Clock.UTC.UTCTime'

根据Hyogeol Lee对本书在线版"getModificationTime does not returns ClockTime type in ghc 7.6.3, but you can use UTCTime instead."的评论,在前奏提示下,我试过:+m Data.Time.Clock.UTC,我收到以下错误:

<no location info>:
Could not find module `Data.Time.Clock.UTC'
It is a member of the hidden package `time-1.4.0.1'.
it is a hidden module in the package `time-1.5'
it is a hidden module in the package `time-1.4.0.1'

ghc-pkg list time的结果是

ghc-pkg list time
/usr/lib64/ghc-7.6.3/package.conf.d
time-1.4.0.1
/home/abelard/.ghc/x86_64-linux-7.6.3/package.conf.d
time-1.5

但我仍然不知道该怎么办?

编辑:根据user2407038,我使用ghc-pkg unregister time-1.5删除时间1.5,之后我得到了类似的错误:

:m +Data.Time.Clock.UTC
Could not find module `Data.Time.Clock.UTC'
It is a member of the hidden package `time-1.4.0.1'.
it is a hidden module in the package `time-1.4.0.1'

Prelude> :m +Data.Time.Clock
<no location info>:
Could not find module `Data.Time.Clock'
It is a member of the hidden package `time-1.4.0.1'.

编辑2 :在阅读了Real World Haskell's chapter 9的输出后,并更改了BetterPredicate.hs的代码: System.Time(ClockTime(..)) Data.Time.Clock(UTCTime) ghc --make BetterPredicate.hs -package time-1.4.0.1 ,以下两种方式对我有用:

  1. 编译文件BetterPredicate.hs:sudo ghc-pkg expose time-1.4.0.1

  2. 使用ghci取消隐藏,然后在Data.Time.Clock下,我可以成功加载模块:m +Data.Time.Clock

  3. *Main Data.Time.Clock> :t UTCTime

    UTCTime :: time-1.4.0.1:Data.Time.Calendar.Days.Day -> DiffTime -> UTCTime

    {{1}}

1 个答案:

答案 0 :(得分:2)

要修复RWH第9章中的BetterPredicate.hs模块,您必须执行以下操作:

  1. import Data.Time.Clock
  2. 将Predicate的定义更改为使用UTCTime而不是ClockTime
  3. 从Control.Exception
  4. 导入SomeException
  5. 定义handleAny函数
  6. handleAnyhandle函数
  7. 中使用saferFileSize代替getFileSize

    import Data.Time.Clock (UTCTime)
    import Control.Exception (bracket, handle, SomeException)
    ...
    type Predicate =  FilePath      -- path to directory entry
                   -> Permissions   -- permissions
                   -> Maybe Integer -- file size (Nothing if not file)
                   -> UTCTime       -- last modified
                   -> Bool
    ...
    handleAny :: (SomeException -> IO a) -> IO a -> IO a
    handleAny = handle
    ...
    saferFileSize path = handleAny (\_ -> ...
    ...
    getFileSize path = handleAny (\_ -> ...
    

    固定代码在这里:http://lpaste.net/116709