[Haskell-cafe] really difficult for a beginner like me...
sebastian.sylvan at gmail.com
Sun May 4 13:17:58 EDT 2008
2008/5/4 Ivan Amarquaye <amarquaye.ivan at hotmail.com>:
> thanks for the tip there....its been four gruesome days and i just don't
> seem to make any understanding of how to implement some changes or create
> some new functions due to the fact that im so new to Haskell and functional
> For the very first case of allowing hyphenated words to be treated as
> single words i manged to successfully do that by adding to the definition of
> the splitWords function to also accept characters such as "-" and it worked
> perfectly after running it.
> The next case posed a headache for me as i have been on it for 3 days now.
> >From my understanding, it means in situations where your writing a
> sentence and you get to the end of the line while writing a word, you
> decide to put a hyphen there and continue on the other line. So the case
> demands that i allow sentences that end with hyphens and continue on the
> next line to drop the hyphen and be a single word on that same line without
> having to continue on the next line so this was how i foresee the input it
> in hugs:
> makeIndex "these are the very same stuff they tell each-\nother"
> should be this: [these],[eachother]. 1 indicates they are on the
> same line and the others are left out as the index takes words greater than
> 4 characters and i have been struggling with this since. i tried on several
> counts to include in the splitwords function to dropWhile "-" is found in
> the words but it turned out an error.I also tried creating a new function to
> do that didnt succeed either can anybody help me out in this regard.....
There are many ways of doing this of course. Perhaps you need to write a
function like so:
-- fixes up hyphenated words
fixupHyphens :: [ (Int, Word) ] -> [ (Int, Word ) ]
fixupHyphens ( (line1, word1):(line2:word2):xs )
| ... check if word1 ends with hyphen and line2 /= line1 ... = ( line1, ...
something .. ) : fixupHyphens xs
| otherwise = (line1, word1):(line2:word2): fixupHyphens xs
fixupHyphens xs = xs
Then you can insert this function in the appropriate place in the makeIndex
function (probably before sorting, as you depend on the words showing up in
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe