Reading and writing files in Haskell
So i've got two files with the following content:
File 1: Tom 965432145 Bill 932121234 File 2: Steve 923432323 Tom 933232323
and i want two merge this two files into one file, and write that out as 'out.txt'. i wrote this function to deal with duplicates (when the same name appears more than once, it choses what number goes into the final file).
the function is called choosing:
choosing :: [String] −> Int −> Int −> Int choosing ("Name_of_person":_) num1 _ = num1 choosing _ num1 num2 | num2 ‘div‘ 100000000 == 2 = num2 | otherwise = num1
My idea was to read the files as tuples, like this:
[(name, phone number),(name,phone number)], so that becomes easier to compare each name and call the function to decide which number goes into the final file. Is this a good idea ? how can i do this ?