[Haskell-cafe] Re: really difficult for a beginner like me...

saaj aliabbas911 at hotmail.com
Wed Mar 24 08:13:29 EDT 2010

saaJamal <aliabbas911 <at> hotmail.com> writes:

U happen to find a way for your problem? I tried a lot for more than a week 
now, but cant do it.

I tried many tutorials but wasnt of any good.

as per the above case study, I need to do is:

1) Allow words to be hyphenated and treat a hyphenated
word as a single word.  However, for those words which are split over two
lines, treat a split word as a single word without the hyphen.

for this i tried:
           fixupHyphens :: [ (Int, Word) ] -> [ (Int, Word ) ]
           fixupHyphens ( (line1, word1):(line2:word2):xs )
           | if (word1, line2) /= line1 = ( line1,word2 ) : fixupHyphens xs
           | otherwise = (line1, word1):(line2:word2): fixupHyphens xs
           fixupHyphens xs = xs

and for including hiphens i added this to the code: 

            splitWords :: Line -> [Word]			--	a)

            splitWords [] = []
            splitWords  line 
            = takeWhile isLetter line :		--	first word in line
	    (splitWords . 			--	split other words
	    dropWhile (not.isLetter) . 	--	delete separators
	    dropWhile isLetter) line	--	other words
             isLetter ch
 	     = 	(('a'<=ch) && (ch<='z'))
  	      ||	(('A'<=ch) && (ch<='Z'))
	      ||      ('-' = ch)

2)Treat a capitalised word (one or more capitals) as being different from the 
word in all lower case (but they should still be sorted alphabetically)unless 
it is at the start of a sentence with only the initial letter capitalised. 

More information about the Haskell-Cafe mailing list