Question: Type check of parameters

Consider the following two test procedures for creation of the same module:

createModule1 := proc(dim::posint)
    module()
        export det;
        det := (x::Matrix(1..dim,1..dim)) -> Determinant(x);
    end module
end proc:

and

createModule2 := proc(A::Matrix(square))
    local dim;
    dim := RowDimension(A);
    module()
        export det;
        det := (x::Matrix(1..dim,1..dim)) -> Determinant(x);
    end module
end proc:

as well as the following code lines calling these:

createModule1(       2 ):-det(IdentityMatrix(2));
createModule2(Matrix(2)):-det(IdentityMatrix(2));

The first line executes unproblematically, while for the second line an error results concerning the dimensionality check 1..dim,1..dim of the matrix. Why is dim available/initialized in the first version, while not in the second?

Please Wait...