2
I’m still learning Haskell (actually just 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 to the second until finished. The problem is that when I run the code it doesn’t make mistakes, 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 also tried this code, but it just subtracted the first 2 values from the list. I know more or less why, but I don’t know how to solve.
sub :: [Float] -> Float
sub [] = 0
sub (x : xs) = subtract (head xs) x
Thanks for the help.