takeWhile (<num+1) xs
says that you want to take elements at the front of the list xs
while the element (not the index!) is less than num + 1
. Since you're comparing num
(which is an Int) with the list elements, the compiler infers that the list elements have to be Int
as well, which contradicts your type declaration.
Without the type declaration, GHC infers that xs
's elements and num
have to be the same type (since you compare list elements with num). This type has to have an Ord
instance (for the comparison) as well as a Num
instance (because of the addition).