GHCI Не удалось загрузить интерфейс для System.Time - PullRequest
0 голосов
/ 28 сентября 2019

Я изучаю Хаскель и пытаюсь создать пример из книги.Когда я загружаю код с помощью команды ": l BetterPredicate" в GHCI, я получаю следующую ошибку:

Prelude> :l BetterPredicate
[1 of 2] Compiling RecursiveContents ( RecursiveContents.hs, interpreted )

RecursiveContents.hs:12:32: warning: [-Wtabs]
    Tab character found here.
    Please use spaces instead.
[2 of 2] Compiling Main             ( BetterPredicate.hs, interpreted )

BetterPredicate.hs:3:1: error:
    Failed to load interface for ‘System.Time’
    Perhaps you meant
      System.CPUTime (from base-4.9.1.0)
      System.Cmd (from process-1.4.3.0)
      System.Mem (from base-4.9.1.0)
    Use -v to see a list of the files searched for.
Failed, modules loaded: RecursiveContents.

Вот код, который я пытаюсь скомпилировать:

import Control.Monad (filterM)
import System.Directory (Permissions (..), getModificationTime, getPermissions)
import System.Time (ClockTime(..))
import System.FilePath (takeExtension)
import Control.Exception (bracket, handle)
import System.IO (IOMode(..), hClose, hFileSize, openFile)

-- Our functions
import RecursiveContents (getRecursiveContents)

type Predicate = FilePath        -- Path to directory entry
              -> Permissions     -- permissions
              -> Maybe Integer   -- file size (Nothing if not file)
              -> ClockTime       -- last modified
              -> Bool
-- TBD
getFileSize :: FilePath -> IO (Maybe Integer)

betterFind :: Predicate -> FilePath -> IO [FilePath]
betterFind p path = getRecursiveContents >>= filterM check
    where check name = do 
              perms <- getPermissions name
              size  <- getFileSize name
              modified <- getModificationTime name 
              return (p name perms size modified)

simpleFileSize :: FilePath -> IO Integer
simpleFileSize path = do
    h <- openFile path ReadMode
    size <- hFileSize h
    hClose
    return size

saferFileSize :: FilePath -> IO (Maybe Integer)
saferFileSize path = handle (\_ -> return Nothing) $ do
    h <- openFile path ReadMode
    size <- hFileSize h
    hClose
    return (Just size)

getFileSize :: FilePath -> IO (Maybe Integer)
getFileSize path = handle (\_ -> return Nothing) $
    bracket (openFile path ReadOnly) hClose $ \h -> do
        size <- hFileSize h
        hClose
        return (Just size)


type InfoP a =  FilePath       -- path to directory entry
             -> Permissions    -- permissions
             -> Maybe Integer  -- file size (Nothing if not file)
             -> ClockTime      -- last modified
             -> a 

pathP :: InfoP FilePath
pathP path _ _ _ = path

sizeP :: InfoP Integer
sizeP _ _ (Just size) _ = size
sizeP _ _ Nothing     _ = -1

equalP :: (Eq a) => InfoP a -> a -> InfoP Bool
--equalP f k = \w x y z -> f w x y z == k
equalP f k w x y z = f w x y z == k

Согласнок документации: http://hackage.haskell.org/package/old-time-1.1.0.3/docs/System-Time.html этот модуль является частью старой библиотеки, поэтому я предполагаю, что мне нужно как-то импортировать ее, но я не уверен, как это сделать, если я не собираю пакет с использованием Cabal (тамнет файла * .cabal) или что-то еще, я просто хочу использовать свой код в GHCI.

1 Ответ

3 голосов
/ 29 сентября 2019

Просто используйте cabal install для глобальной установки пакета

$ cabal install old-time

Это выдаст вам предупреждение, но это нормально, если вы просто используете его для поддержки ghci.

Также обратите внимание документация предупреждает:

Эта библиотека устарела, вместо этого посмотрите Data.Time в пакете времени.

...