Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING SML In this assignment, you will write your own datatype and use case expressions and pattern matching to traverse it. The datatype you will

image text in transcribed
USING SML
In this assignment, you will write your own datatype and use case expressions and pattern matching to traverse it. The datatype you will write represents the directory structure of a file system in a computer. 1. Write a datatype binding for a file system object fsobject that can be one of the following: A file which has two fields: a name (stored as a string) and the size of the file (stored as an int) A directory which has two fields: a name (stored as a string) and a list of the file system objects the directory contains A link which has two fields: a name (stored as a string) and the path to the file or directory that it links to (stored as a string) 2. Create a value myFs of type FsObject that stores a file system object with the following hierarchy: dira +--- dir 1 dirc +---- filel (4096 B) +--- file2 (2097152 B) +--- linkx -> dirA/dir/file4 linky -> dirA/dir/file4 dir +--- File3 (4194304 B) file4 (128 B) linkz -> dir/dir/dir/filel 3. Write a function totalSize that takes a value of type FsObject and returns the total size of all the files in the hierarchy. 4. Write a function containsLinks that takes a value of type FsObject and returns true if the hierarchy contains any links, and false otherwise. 5. Write a function getFilesLargerThan that takes a value of type FsObject and an integer n and returns a string list with the names of all the files larger than n. It is okay to use the operator @ for concatenating two lists (e.g., xs @ ys concatenates the two lists xs and ys). 6. Write a function countLinksto that takes a value of type FsObject and a string p and returns the number of links that point to the path p. Evaluating a correct homework solution should generate the bindings below. However, keep in mind that generating these bindings does not guarantee that your solutions are correct. Make sure to test your functions before submitting. datatype FsObject = val myFS = Comitted> val totalSize = fn : FsObject -> int val containsLinks = fn : FsObject -> bool val getFilesLargerThan = fn : FsObject * int -> string list val countLinksTo = fn : FSObject * string -> int In this assignment, you will write your own datatype and use case expressions and pattern matching to traverse it. The datatype you will write represents the directory structure of a file system in a computer. 1. Write a datatype binding for a file system object fsobject that can be one of the following: A file which has two fields: a name (stored as a string) and the size of the file (stored as an int) A directory which has two fields: a name (stored as a string) and a list of the file system objects the directory contains A link which has two fields: a name (stored as a string) and the path to the file or directory that it links to (stored as a string) 2. Create a value myFs of type FsObject that stores a file system object with the following hierarchy: dira +--- dir 1 dirc +---- filel (4096 B) +--- file2 (2097152 B) +--- linkx -> dirA/dir/file4 linky -> dirA/dir/file4 dir +--- File3 (4194304 B) file4 (128 B) linkz -> dir/dir/dir/filel 3. Write a function totalSize that takes a value of type FsObject and returns the total size of all the files in the hierarchy. 4. Write a function containsLinks that takes a value of type FsObject and returns true if the hierarchy contains any links, and false otherwise. 5. Write a function getFilesLargerThan that takes a value of type FsObject and an integer n and returns a string list with the names of all the files larger than n. It is okay to use the operator @ for concatenating two lists (e.g., xs @ ys concatenates the two lists xs and ys). 6. Write a function countLinksto that takes a value of type FsObject and a string p and returns the number of links that point to the path p. Evaluating a correct homework solution should generate the bindings below. However, keep in mind that generating these bindings does not guarantee that your solutions are correct. Make sure to test your functions before submitting. datatype FsObject = val myFS = Comitted> val totalSize = fn : FsObject -> int val containsLinks = fn : FsObject -> bool val getFilesLargerThan = fn : FsObject * int -> string list val countLinksTo = fn : FSObject * string -> int

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions