Implement file system functions
This commit is contained in:
parent
f71ef5723f
commit
c631790636
|
@ -39,7 +39,11 @@ example = Dir "root"
|
|||
besprochen.
|
||||
-}
|
||||
filesystem :: (Name -> FileSizeKB -> b) -> (Name -> [b] -> b) -> FileSystem -> b
|
||||
filesystem file dir fs = error "fixme"
|
||||
filesystem file dir fs = case fs of
|
||||
Dir name items ->
|
||||
dir name (map (filesystem file dir) items)
|
||||
File name fileSize ->
|
||||
file name fileSize
|
||||
|
||||
{-
|
||||
Ausgehend von der Funktion 'filesystem' wollen wir nun konkrete Funktionen
|
||||
|
@ -52,7 +56,10 @@ filesystem file dir fs = error "fixme"
|
|||
Verzeichnisstruktur zurück gibt. Verwenden Sie die Funktion 'filesystem'.
|
||||
-}
|
||||
size :: FileSystem -> Int
|
||||
size = filesystem (error "fixme") (error "fixme")
|
||||
size = filesystem (\_ -> \fileSize -> fileSize) (\_ -> \sizes -> sum sizes)
|
||||
-- >>> size example
|
||||
-- 14606
|
||||
--
|
||||
|
||||
{- Datei abfragen
|
||||
Implementieren Sie die Funktion 'existsFile', die bei einer gegebenen
|
||||
|
@ -60,7 +67,13 @@ size = filesystem (error "fixme") (error "fixme")
|
|||
Namen zu finden ist. Verwenden Sie die Funktion 'filesystem'.
|
||||
-}
|
||||
existsFile :: Name -> FileSystem -> Bool
|
||||
existsFile name = filesystem (error "fixme") (error "fixme")
|
||||
existsFile name = filesystem
|
||||
(\fileName -> \_ -> name == fileName)
|
||||
(\_ -> \items -> or items)
|
||||
|
||||
-- >>> existsFile "rome1.jpg" example
|
||||
-- True
|
||||
--
|
||||
|
||||
{- Pfade
|
||||
Ein Pfad ist eine Liste von Namen.
|
||||
|
@ -80,7 +93,10 @@ findAll :: Name -> FileSystem -> [Path]
|
|||
findAll name = filesystem file dir
|
||||
where
|
||||
file :: Name -> Int -> [Path]
|
||||
file n _ = error "fixme"
|
||||
file n _ = if n == name then [[n]] else []
|
||||
dir :: Name -> [[Path]] -> [Path]
|
||||
dir n subs = error "fixme"
|
||||
dir n subs = map (\path -> [n] ++ path) (concat subs)
|
||||
|
||||
-- >>> findAll "notes.txt" example
|
||||
-- [["root","desktop","notes.txt"],["root","pictures","holiday2018","notes.txt"]]
|
||||
--
|
||||
|
|
Loading…
Reference in a new issue