Im Anfänger und ich versuche, Dateien eines Ordners zu lesen nennt "Papiere" (Sie können den Baum meines Projekts in der angehängten Datei sehen). Im diesen Code für es tun: Mein Haskell-Code hat einen Fehler zu openFile mit Haskell
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
pathFicheros <- getDirectoryContents directorio
printAll pathFicheros
return (leerDocumentos pathFicheros)
printAll xs = if null xs -- If the list is empty
then return() -- then we're done, so we quit.
else do print (head xs) -- Otherwise, print the first element
printAll (tail xs) -- then print all the other elements.
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
aber im den nächsten Fehler mit:
*** Ausnahme:.: Openfile: Ungeeignete Typ (ein Verzeichnis)
Jemand kann Hilf mir bitte?
Was ist Ihre 'Hauptfunktion'? – ErikR
@ErikR ist dies: Modul Haupt wo main :: IO() main = undefined –
Sie versuchen, zu öffnen '.' und' ..' (die sind enthalten https sehen: //hackage.haskell. org/package/verzeichnis-1.2.6.3/docs/System-Verzeichnis.html # v: getDirectoryContents) - Sie sollten wahrscheinlich beginnen mit 'listDirectory' anstatt – Carsten