Here is the code:
listhalve :: [a] -> ([a],[a])
listhalve (x:xs)
| length [x] == length xs = ([x],xs)
| length [x] < length xs = listhalve ([x] ++ head xs : tail xs)
| length [x] > length xs = ([x],xs)
There are no error messages when I run or compile it, it just runs forever in the case of non-pair lists.
I’m aware of different ways to write this function that work. I just want to know what’s wrong with this code specifically.
>Solution :
Consider that listhalve ([x] ++ head xs : tail xs) is the same as listhalve ([x] ++ xs) which is the same as listhalve (x:xs) which is what you went in with, so endless recursion results.