다음과 같은 기능을 구현 중입니다. 사용자가 HTTP 요청을 통해 디렉토리 내용을 요청합니다. 요청시 디렉토리 경로가 전달됩니다. 이에 대한 응답으로 해당 디렉토리 경로에 대한 파일 목록을 포함하는 JSON을 보냅니다. IO 오류 처리가 처리됩니다. 대부분의 부분을 구현했습니다. 하지만 오류가 발생합니다. 오류 :IO로 인해 매개 변수 유형이 잘못되었습니다.
getInfoOfDirR::Handler Value
getInfoOfDirR = do
-- files will have type IO (Either IOException [FilePath])
files <- fmap (getListOfFiles.(Data.Text.unpack).fromJust) $ lookupGetParam "dirpath"
getJsonRepForFiles files
파일 목록을 가져옵니다 기능 :에있는 파일의 JSON 표현을 가져옵니다
-- This eliminates the hidden files from the results
getListOfFiles::FilePath -> IO (Either IOException [FilePath])
getListOfFiles fpath = try (fmap (filter $ not.isHiddenFile) $ FS.getDirectoryContents fpath)::IO (Either IOException [FilePath])
기능을 다음과 같이
Couldn't match expected type ‘Either IOException [FilePath]’ with actual type ‘IO (Either IOException [FilePath])’ • In the first argument of ‘getJsonRepForFiles’, namely ‘files’
코드 조각입니다 디렉토리 :
getJsonRepForFiles::Monad m => (Either IOException [FilePath]) -> m Value
getJsonRepForFiles (Left e) = returnJson $ "An error occurred" ++ show e
getJsonRepForFiles (Right files) = returnJson files
getInfoOfDirR
의 유형은 Handler Value
입니다. 하스켈의 Yesod 프레임 워크에서이를 구현 중입니다. 하스켈을 처음 접했습니다. 왜 오류가 발생하는지 이해하고 있습니다. 그러나 나는 그것을 고칠 수 없다. 도와주세요. 미리 감사드립니다.
'liftIO'를 사용했지만 문제가 해결되지 않았습니다 –