COMP 15
Programming Assignment 3
Spelling Checker
Assigned:
Wednesday Sep 22, 1999
Due:
Thursday Oct 7, 1999

Problem Description

In this assignment you are asked to construct a program that, given a text string, displays the text on the screen with all misspelled words marked. For our purposes, we consider a word to be misspelled if it doesn't appear in a dictionary supplied as a list of strings.

You should construct a Haskell function

     spellcheck :: String -> [String] -> IO ()
so that given an input text string text and a list of words in a dictionary dictionary, the expression spellcheck text dictionary shows successive lines of text with 2 additional spaces added to the left margin. Each line of text that contains a word not in dictionary is flagged by placing a "*" in the left margin, and by a string of "X" characters placed underneath the word in error.

Here is an example. Suppose that text contains the following string

     "The first line,\nand the  second lyne.\nThe end."
and the dictionary d contains the list of strings
     ["and", "end", "first", "line", "or", "the"]
Then spellcheck text dictionary should display the following:
       The first line,
     * and the  second lyne.
                XXXXXX XXXX
       The end.

A word is composed entirely of consecutive alphabetic characters and is terminated by a non-alphabetic character (for example, a space, a newline or a period) or by the end of the string in which it appears. Words in a dictionary contain only lower-case characters, and capitalization should be ignored in determining whether a word appears in the dictionary.

The string of "X" characters marking the word in error should appear directly below the letters making up the word, but should not extend to include punctuation or any spaces. The output lines should reflect the input lines in text exactly, including spacing.

In grading this assignment we will place additional weight on the clarity and simplicity of your program.

Supplying input to your program

The variables text and dictionary should be defined in a separate Haskell module called Text.hs that appears in the same directory as your program for this assignment. At the head of your program you should import Text which will allow you to run your program by executing putStr (spellcheck text dictionary). Of course you can create several different text and dictionary variables in Text.hs to facilitate the testing of your program with different inputs.


Submission Procedure

The times available for submission of program 3 are (tentatively)


$ Revised: Wed Sep 22, 1999 by prins@cs.unc.edu