13 | (+) : Matrix -> Matrix -> Matrix
14 | M a1 b1 c1 d1 + M a2 b2 c2 d2 = M (a1 + a2) (b1 + b2) (c1 + c2) (d1 + d2)
18 | (*) : Matrix -> Matrix -> Matrix
19 | M x11 x12 x21 x22 * M y11 y12 y21 y22 =
20 | M (x11 * y11 + x12 * y21)
21 | (x11 * y21 + x12 * y22)
22 | (x21 * y11 + x22 * y21)
23 | (x21 * y21 + x22 * y22)
29 | inverse : Matrix -> Maybe Matrix
30 | inverse (M a b c d) =
31 | let det := a * d - b * c
32 | in if abs det < 1.0e-12 then Nothing
33 | else Just $
M (d / det) (negate b / det) (negate c / det) (a / det)