I'm learning myself Haskell, and for one exercise I have to calculate the determinant for a Matrix. I refreshed the mathematical way to do it and emulated it in code, but for some reason it's looping infinitely. I've been entering stuff into GHCi for hours trying to pinpoint what's causing it but I can't find it.
type Vector = [Float]
type Matrix = [Vector]
determinant :: Matrix -> Float
determinant [] = 0
determinant [[a,b],[c,d]] = (a*d) - (b*c)
determinant (vec:mat) = dethelper vec mat 0
dethelper :: Vector -> Matrix -> Int -> Float
dethelper vec mat n
| vec == [] = 0
| n == length vec = 0
| even n = (vec!!n * (determinant $ map (dropAt n) mat)) - (dethelper vec mat n+1)
| otherwise = (vec!!n * (determinant $ map (dropAt n) mat)) + (dethelper vec mat n+1)
dropAt :: Int -> Vector -> Vector
dropAt x xs = (fst spl) ++ (tail $ snd spl)
where spl = splitAt x xs
dethelper vec mat n+1means(dethelper vec mat n)+1notdethelper vec mat (n+1), which is presumably what you wanted.