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

Daniel Fischer daniel.is.fischer at web.de
Wed Mar 24 09:44:24 EDT 2010


-----Ursprüngliche Nachricht-----
Von: saaj [
Gesendet: 24.03.2010 13:13:29
An: haskell-cafe at haskell.org
Betreff: [Haskell-cafe] Re: really difficult for a beginner like me...

>saaJamal [ 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
>

It's probably easier to treat the hyphens before pairing the words with the line-numbers.
If you needn't care about words containing a hyphen (like line-numbers above), a simple preprocessor

fixHyphens :: String -> String
fixHyphens ('-':'\n':more) = (move rest of the word before the newline and remove hyphen)
fixHyphens (c:cs) = c: fixHyphens cs
fixHyphens "" = ""

should do the trick.

>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
>            where
>             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. 
>
>
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe at haskell.org
>http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list