I'm still learning Haskell (actually only started about 2 days ago) with a basic C # knowledge.
In this piece of code the code is supposed to iterate several times in a list and subtract the first value from the second until it finishes. The problem is that when I run the code it does not give errors, but it goes into a kind of infinite loop, because nothing happens.
sub :: [Float] -> Float
sub [] = 0
sub (x : xs) = sub ( subtract (head xs) x : xs)
I've also tried this code, but it just subtracts the first 2 values from the list. I know more or less why, but I do not know how to solve it.
sub :: [Float] -> Float
sub [] = 0
sub (x : xs) = subtract (head xs) x
Thanks for the help.