我正在尝试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
,以下两种方式对我有用:
编译文件BetterPredicate.hs:sudo ghc-pkg expose time-1.4.0.1
使用ghci
取消隐藏,然后在Data.Time.Clock
下,我可以成功加载模块:m +Data.Time.Clock
:
*Main Data.Time.Clock> :t UTCTime
UTCTime
:: time-1.4.0.1:Data.Time.Calendar.Days.Day -> DiffTime -> UTCTime
{{1}}
答案 0 :(得分:2)
要修复RWH第9章中的BetterPredicate.hs
模块,您必须执行以下操作:
handleAny
函数handleAny
和handle
函数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