|
-
Nov 17th, 2005, 12:30 PM
#1
Thread Starter
Frenzied Member
haskell function question
Code:
type Word = String
italplural :: Word -> Word
italplural (x:xs)
| (length(xs) == 0) = if (x == 'e') || (x == 'i') then x == 'o'
can anyone aee why it doesnt work? im trying to make the function replace ever letter on the end of the word with o (if its a 'e' or a 'i'), i've tried to start it off by checking if the tail is empty, and if the head of the word is e oe i, but it doesnt work, any ideas?
-
Nov 17th, 2005, 05:19 PM
#2
New Member
Re: haskell function question
Hello pouncer, im not sure I understand you fully, do you want to replace every word, that ends in 'e' or 'i' with an 'o', or do you want to add an 'o' to the end of a word beginning with 'e' or 'i'?
and if the head of the word is e oe i
Thats what you would be doing by this.
I wrote a function that replaces all the e's and i's with o's. I hope it helps a little, I can maybe help more if you let me know about the above question.
Code:
type Word = String
italplural :: Word -> Word
italplural [] = []
italplural (x:xs)
| (x == 'e') || (x == 'i') = 'o' : italplural xs
| otherwise = x : italplural xs
Craig
-
Nov 18th, 2005, 08:02 AM
#3
Thread Starter
Frenzied Member
Re: haskell function question
thank you very much for the reply,
I want to replace every word, that ends in 'e' or 'i' with an 'o'
and
replace every word, that ends in 'a' with an 'e'
e..g
pizza = pizze
helle = hello
a = e
i = o
and any word which doesnt end in a,e,i .. i just have to leave them as is, e.g.
hey = hey
f = f
erm = erm
etc..
Thanks, any help would be brilliant!!
Last edited by Pouncer; Nov 18th, 2005 at 08:07 AM.
-
Nov 19th, 2005, 06:26 PM
#4
New Member
Re: haskell function question
Hey Pouncer, maybe some sort of input argument of the form;
Code:
italplural :: Word -> Word
italplural [] = []
italplural (x:y:xs)
may work, as you see it takes the first two elements or two 'heads' you could say, and adds them onto the tail of the list. We can treat this as a list because a String is the same as a [Char] (a list of characters).
I have tried it out tonight but got only so far, I will give it another bash and post something up tommorow for you.
Edit... I forgot to mention..the whole point of this would be to test if 'y' is a blank space ( ' ' ), then you would know that your at the end of the word.
Craig
-
Nov 26th, 2005, 11:02 AM
#5
New Member
Re: haskell function question
Hey again, sorry for the delay.
I have come up with a new idea for you;
The standard prelude contains a function called "last". This function will return the last element(letter) of a word.
If you incorporate last into a simple recursive statement, then you have solved your problem.
Craig
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|