On Tue, 24 Mar 2009, Daniel Yokomizo wrote:

If we try the other approach, we need to express the totality of
invMat by restricting its domain, so we can add, for example, a
phantom type to Matrix to signal it is invertible. As you need to
construct the Matrix before trying to invert it you can always make
the constructors smart enough to bundle the Matrix with such
properties. Of course there's need to do some runtime verifications
earlier, but the clients of invMat are required to do the verification
earlier or pass it to their clients (up to the level that can handle
with this issue):

data Invertible
tryInvertible :: Matrix a -> Maybe (Matrix Invertible)
invMat :: Matrix Invertible -> Matrix Invertible

This would be a very elegant solution. However when it comes to floating point numbers I'm afraid there are no much other ways than inverting a matrix if you want to know if it is invertible. You may however use representations of a matrix (like an LU decomposition or a QR decomposition) internally that are half-way of inversion.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to