Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q3: Files and Directories [30 pts] We can represent a directory structure using the following Haskell datatype: data Entry File String Int - file: name
Q3: Files and Directories [30 pts] We can represent a directory structure using the following Haskell datatype: data Entry File String Int - file: name and size l Dir String [Entry]directory: name and child entries For example, the value: homedir -Dir "home I File "todo" 256 , Dir "HWO" File "Makefile" 575 ] , Dir "HW1" [ File "Makefile" 845, File "HM1.hs" 3007] represents the following directory structure: home 1---todo (256 bytes) I-HwO IHW1 I--Makefile (575 bytes) I---Makefile (845 bytes) IHW1.hs (3007 bytes) In your solutions you can use any library functions on integers (e.g, arithmetic operators), but only the following functions on lists: (String -> String -> Bool --equality on strings append on any lists map (a -b) [a] - [b] filter: (a -> Bool) -> [a] > [a] foldr (a -b-> b) -> b -> [a] -> b foldl :: (b-> a-> b) -> b-> [a] -> b Implement the function size that computes the total size of an entry in bytes. You are allowed to introduce a helper function using a where clause, although we encourage you to use a higher-order function instead Your implementation must satisfy the following test cases size (File "todo 256) > 256 wm> 0 >4683256 575 +845 3007 size (Dir "haskell-jokea D) size honedir size:: Entry Int Q3: Files and Directories [30 pts] We can represent a directory structure using the following Haskell datatype: data Entry File String Int - file: name and size l Dir String [Entry]directory: name and child entries For example, the value: homedir -Dir "home I File "todo" 256 , Dir "HWO" File "Makefile" 575 ] , Dir "HW1" [ File "Makefile" 845, File "HM1.hs" 3007] represents the following directory structure: home 1---todo (256 bytes) I-HwO IHW1 I--Makefile (575 bytes) I---Makefile (845 bytes) IHW1.hs (3007 bytes) In your solutions you can use any library functions on integers (e.g, arithmetic operators), but only the following functions on lists: (String -> String -> Bool --equality on strings append on any lists map (a -b) [a] - [b] filter: (a -> Bool) -> [a] > [a] foldr (a -b-> b) -> b -> [a] -> b foldl :: (b-> a-> b) -> b-> [a] -> b Implement the function size that computes the total size of an entry in bytes. You are allowed to introduce a helper function using a where clause, although we encourage you to use a higher-order function instead Your implementation must satisfy the following test cases size (File "todo 256) > 256 wm> 0 >4683256 575 +845 3007 size (Dir "haskell-jokea D) size honedir size:: Entry Int
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started