a) Your program is slowed down because lines from the file is read one line by one, i.e. there's lazy IO at work. Have you tried your code on a list that's loaded in the memory as a whole at once?
b) The cost of dereferencing the next link in a list overwhelms the cost of computing one answer. Have you tried using a tree instead?