Head/tail functions expecting int and erroring on [int]
I wrote this garbled mess, which is supposed to take two sorted lists and return a merged sorted list:
mergeLists list1 list2 = if head list1 > head list2 then [head [list2]++mergeLists (list1) (tail list2)] else if head list1 < head list2 then [head [list1]++mergeLists (tail list1) (list2)] else [head [list2]++head [list1]++mergeLists (tail list1) (tail list2)]
Im fairly sure the logic checks out, by building a new list from taking the smallest head value it should always work. There is no edge case for when one list is empty yet, but there will be once I figure out these errors.
My problem is the 3 errors all basically the same, complaining that whenever i pass an int it wants an [int] and whenever i pass an [int] it wants an int. Its driving me mad. It seems to be based on the head/tail calls because when i add extra brackets to make something like head [list1] the errors change. It may be to do with the ++ though.
I do not know Haskell, or functional programming, very well at all. Can someone please point out what i have done wrong?
Submitted February 23, 2018 at 08:07PM by Jamma003
via reddit http://ift.tt/2BMsub9