
5 Mar
2010
5 Mar
'10
7:19 a.m.
Hi,
Im self learner in Haskell. And im stuck in a small place which I tried searching in google but couldn't find Proper answer
I have some values in a string, Im removing them one by one from the string (word by word) and I want to put them in a tuple. Because it contain Integers and Strings.
Can someone help me
Maybe something like this? pairs :: String -> [(String,Integer)] pairs s = f (words s) [] where f [] acc = reverse acc f (i:[]) acc = reverse ((i,undefined):acc) f (i:v:r) acc = f r ((i,read v):acc) Key points to look at: accumulator (acc with cons : ), recursion (f), pattern matching (i:v:r), undefined (if the data is not pairs).