
hi I am trying to create a function that uses the words function... I am doing the same thing to each element in a list so I am using mapping techniques. Code... --Define the main first function rStrings2Results :: ([String] -> String) -> [[String]] -> [String] rStrings2Results f(head:tail) = (f head : rStrings2Results f tail) I just want take a list and on the first member ("hello my name is ryan") to say [("hello", "my", "name", "is", "ryan"),..............] using the words function. _________________________________________________________________ 100’s of Music vouchers to be won with MSN Music https://www.musicmashup.co.uk

Ryan Bloor
I am trying to create a function that uses the words function... I am doing the same thing to each element in a list so I am using mapping techniques.
And it doesn't work?
--Define the main first function rStrings2Results :: ([String] -> String) -> [[String]] -> [String] rStrings2Results f(head:tail) = (f head : rStrings2Results f tail)
Note that you will shadow 'head' and 'tail' from the Prelude here. Ideally, you should choose different names, I think (x:xs) is idiomatic, or perhaps (l:ls) for "a list" and "lists" in this case. I notice 'rStrings2Results' looks very much like a reimplementation of a common Prelude function, presumably that is intentional?
I just want take a list and on the first member ("hello my name is ryan") to say [("hello", "my", "name", "is", "ryan"),..............] using the words function.
You really want to return a tuple here, and not a list? You then would have to have a fixed number of words in each string. If you mean to convert "hello my name.." to ["hello","my","name.."], well, I guess you know how to achieve that. -k -- If I haven't seen further, it is by standing in the footprints of giants

On 08/11/2007, Ryan Bloor
hi
I am trying to create a function that uses the words function... I am doing the same thing to each element in a list so I am using mapping techniques.
Code...
--Define the main first function rStrings2Results :: ([String] -> String) -> [[String]] -> [String] rStrings2Results f(head:tail) = (f head : rStrings2Results f tail)
Your description of the problem doesn't relate to the type signature or the solution you have here. I assume the function f which you pass in is meant to be 'words'? In that case, the type signature should be (String -> [String]), not the other way round (which would be unwords, or concat, for example). The example solution as it stands also doesn't deal with the empty list. The pattern match against [] will fail.
I just want take a list and on the first member ("hello my name is ryan") to say [("hello", "my", "name", "is", "ryan"),..............] using the words function.
I'm still not completely clear on what you want, so maybe you can clarify. I guess it's something like: ["my name is ryan", "i am learning haskell", "it is fun"] -> [["my","name", "is", "ryan"],["i am learning haskell", "it is fun"]] Is this about right? If so, then your type signature should be: f :: (String -> [String]) -> [String] -> [[String]] Although as another poster mentioned, you might think about separating out the head and the tail of the list. It seems to just be a two-element list which could be easily represented as a tuple. f' :: (String -> [String]) -> [String] -> ([String], [String]) Of course I could be very wrong with my interpretation of your problem! Cheers, D. -- Dougal Stanton dougal@dougalstanton.net // http://www.dougalstanton.net
participants (3)
-
Dougal Stanton
-
Ketil Malde
-
Ryan Bloor