[Haskell-cafe] words function
ketil+haskell at ii.uib.no
Thu Nov 8 05:57:42 EST 2007
Ryan Bloor <ryanbloor at hotmail.com> writes:
> 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
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.
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe