Technically, a matrix’s entries may be any type, and some fully polymorphic matrix functions such as matrix-row and matrix-map operate on any kind of matrix. Other functions, such as matrix+, require their matrix arguments to contain numeric values.
> (matrix-conjugate (matrix [[1.0+2.0i 2.0+3.0i 3.0+4.0i] [4.0+5.0i 5.0+6.0i 6.0+7.0i]]))
- : (Array Float-Complex)
(array #[#[1.0-2.0i 2.0-3.0i 3.0-4.0i] #[4.0-5.0i 5.0-6.0i 6.0-7.0i]])
In many matrix operations, such as inversion, failure is easy to detect during computation, but is just as expensive to detect ahead of time as the operation itself. In these cases, the functions implementing the operations accept an optional failure thunk, or a zero-argument function that returns the result of the operation in case of failure.
Default failure thunks usually raise an error, and have the type (-> Nothing). For such failure thunks, (U F (Matrix Number)) is equivalent to (Matrix Number), because Nothing is part of every type. (In Racket, any expression may raise an error.) Thus, in this case, no explicit test for values of type F is necessary (though of course they may be caught using with-handlers or similar).
> (matrix+ (identity-matrix 2) (matrix []))
- : (Array Index)
matrix-map: matrices must have the same shape; given (array
#[#[1 0] #[0 1]]) (array #[#])