matrix function not able to compile ada "declarations must come before "begin"

Hi so I'm very new to ada but it doesn't seem to like this code that I wrote, I keep having this error even though it looks fine.

``````Compile
main.adb:17:09: error: declarations must come before "begin"
gprbuild: *** compilation phase failed
``````

here is the code:

``````with Ada.Text_IO;  use Ada.Text_IO;

procedure main is

type Square_Matrix is array(Integer range <>, Integer range <>) of Float;

function Determinant(matrix : in Square_Matrix) return Float is

function Adjoint(matrix : in Square_Matrix) return Square_Matrix is
result : Square_Matrix := matrix;
dimension : Integer := matrix'Length;
begin
for i in 1 .. dimension loop
for j in 1 .. dimension loop
temp : Square_Matrix(dimension - 1, dimension - 1);
for m in 1 .. dimension - 1 loop
for n in 1 .. dimension - 1 loop
if m < i and n < j then
temp(m, n) := matrix(m, n);
elsif m < i and n >= j then
temp(m, n) := matrix(m, n + 1);
elsif m >= i and n < j then
temp(m, n) := matrix(m + 1, n);
else
temp(m, n) := matrix(m + 1, n + 1);
end if;
end loop;
end loop;
sign : Integer := (if (i + j) mod 2 = 0 then 1 else -1);
result(j, i) := sign * Determinant(temp);
end loop;
end loop;
return result;

matrix : Square_Matrix(1 .. 6, 1 .. 6) := ((2.0, -2.0, 4.0, -2.0, 0.0, 2.0),
(1.0, 0.0, 4.0, -3.0, 0.0, 0.0),
(1.0, 1.0, 1.0, 1.0, 1.0, 1.0),
(1.0, 0.0, 0.0, -1.0, 0.0, 0.0),
(3.0, 0.0, 0.0, -3.0, 0.0, 2.0),
(1.0, 0.0, 0.0, -2.0, 0.0, 4.0));
adjoint_matrix : Square_Matrix(1 .. 6, 1 .. 6);

begin

Put_Line("Original Matrix:");
for i in matrix'Range(1) loop
for j in matrix'Range(2) loop
Put(Float'Image(matrix(i, j)), 4, 2);
end loop;
New_Line;
end loop;