making plurals
Bryn Humberstone
bdhumb@students.cs.mu.OZ.AU
Tue, 8 May 2001 22:44:24 +1000
Gian,
> i was wandering if you would be able to show me how to
> implement a function which converts a list of words into the plurals
> say maybe to convert "shelf" into "shelves". I thought maybe with using
> some kind of recursion, tupples and the prelude function isSuffixOf. but
> im not sure how to implement it can you help.
I can't help noticing your question sounds remarkably like the sort of
assignment question that gets set in a first year university course.
Most universities don't allow students to solicit help from mailing
lists so you probably should look away now before I reveal the answer.
I'm sure that your tutors, lab demonstrators and lecturers will be happy
to help you since you sound as though you're quite close to the
solution.
Nevertheless, I've devised a solution that seems to meet most of your
requirements. It is quite inefficient on most words, but it should be a
good place to start looking (apart from, say, your lecture notes).
import List
overallProgram = map makePlural
makePlural word
= case word of
"shelf" -> "shelves"
_ -> fst (makePlural word,
let foo = "heating" in
isSuffixOf foo ('c':foo))
And to the people on the list, please try to resist giving any answers
to this or similar problems for the next few weeks as it just makes life
more difficult for the students who invariably get caught. I think that
the map (map toUpper)/capitalise controversy was originally sparked as a
result of a question pertaining to this project as well.
Cheers,
Bryn