

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A homework assignment for a fall 2005 haskell course, where students are required to write a function 'justify' that justifies text documents by replacing whitespace to create smooth left and right margins. The function should ensure each line is a specific length, includes as many words as possible, and separates words with consistent spacing. The document also includes instructions for documentation and submission.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


22C:111 — Fall 2005 page i Homework V (100 points) This problem involves a common text processing computation — fully (left and right) justifying a document. That is, replacing the “whitespace” in a text document so that there are smooth left and right margins. In Haskell, text will simply consist of a String. For this problem, the term “whitespace” will refer to occurrences of spaces (' '), tabs ('\t'), and newlines or carriage returns ('\n'). The term “word” will denote a maximal length substring of non-whitespace characters. The term “line” will denote substrings enclosed by newline characters (or the beginning or end of string). Each string will be decomposed into a sequence of “words” separated by whitespace. Write a Haskell definition for a function 'justify' that takes two arguments, an integer n>0 and a string 'text'. The resulting string should consist of the words from text with all whitespace replaced so that each line (except the last):
22C:111 — Fall 2005 page ii The putStr function can only be used at the top-level since its result type is not String. Hence display of test cases will be shown by expressions of the form putStr (justify … ). Special instructions The solutions to this problem must include documentation (in-line comments, and a separate write-up as appropriate) that makes it clear both what general method you used in constructing the program, and how the details of the program accomplish that method. You need to run test cases that exercise every component of your code, and include documentation that justifies that your test data meets this condition. It is not the grader’s responsibility to figure out how you wrote the program and whether it is correct — it is your responsibility to explain your program and convince the grader it is completely tested and correct. Full credit will not be awarded, even for (apparently) correct programs, unless you do so. In addition to the “paper submission” of your tests and source code, you should submit your Haskell script file electronically using the 'submit' command to course id c111 in directory Hwk5.