новичок Im и им пытаются читать файлы из моей папки «документы» (в том же пути, что сценарии), но у меня есть следующая ошибка:Как я могу читать файлы в haskell?
Couldn't match expected type ‘[FilePath]’
with actual type ‘IO [FilePath]’
In the first argument of ‘leerDocumentos’, namely ‘pathFicheros’
In the first argument of ‘return’, namely
‘(leerDocumentos pathFicheros)’
Может быть, это не одна ошибка, что у меня есть на моем коде, поэтому я надеюсь, что кто-то может помочь мне заполнить мой модуль.
код моего читателя:
module LeerDocumentos2 where
import System.Directory
import System.IO.Unsafe
import System.IO()
import Documento
reader :: IO [Documento]
reader = do
setCurrentDirectory "papers"
directorio <- getCurrentDirectory
putStrLn directorio -- Directorio donde estan los documentos
let pathFicheros = getDirectoryContents directorio
return (leerDocumentos pathFicheros)
leerDocumentos :: [FilePath] -> [Documento]
leerDocumentos [] = []
leerDocumentos (x:xs) = do
let documento = unsafePerformIO (leerDocumento x)
[documento]++ leerDocumentos xs
leerDocumento :: String -> IO Documento
leerDocumento ruta = do
putStrLn ruta
texto <- readFile ruta
let docuAux = lines texto
let revista = obtenerRevista docuAux
let idd = obtenerID docuAux
let anno = obtenerAnno docuAux
let titulo = obtenerTitulo docuAux
let resumen = obtenerResumen docuAux
let secciones = obtenerSecciones docuAux
let documento = D (revista,idd,anno,titulo,resumen,secciones)
return documento
obtenerRevista :: [String] -> String
obtenerRevista [] = []
obtenerRevista texto = head texto
obtenerID:: [String] -> String
obtenerID [] = []
obtenerID texto = head (drop 1 (texto))
obtenerAnno:: [String] -> String
obtenerAnno [] = []
obtenerAnno texto = head (drop 2 (texto))
obtenerTitulo:: [String] -> String
obtenerTitulo [] = []
obtenerTitulo texto = head (drop 4 (texto))
obtenerResumen:: [String] -> String
obtenerResumen [] = []
obtenerResumen texto = head (drop 6 (texto))
obtenerSecciones :: [String]->[String]
obtenerSecciones [] = []
obtenerSecciones texto = quitarSeparador (drop 8 (texto))
quitarSeparador :: [String] -> [String]
quitarSeparador [] = []
quitarSeparador (s:sn) = if s == "--" || length s <= 1 then --Para quitar lineas blancas
quitarSeparador sn
else
s:quitarSeparador sn
и это код моего модуля Documento:
модуль Documento где
data Documento = Documento {revista :: String, idD :: String, anno :: String, titulo :: String, resumen :: String, secciones :: [String]} deriving (Eq)
type Documentos = [Documento]
спасибо !!
сначала забудьте, что 'unsafePerfomIO' даже существует, тогда используйте' pathFicheros <- getDirectoryContents directorio' вместо 'let' – Carsten