My understanding is that in Hoare Type Theory every imperative statement has a type of the form {Pre}res:T{Post}
where T
is the type of the result of the computation and Pre
and Post
are propositions representing respectively the pre and postconditions of the statement and res
is the result of type T
which can appear in the postcondition.
Given the following program in pseudo-C:
int i=0;
int*p=&i;
*p=1
return i;
How can Hoare type theory represent the the fact that i
must be 1?After all,it's not clear i
is modified in the above snippet,and it can be hidden even from the programmer if we begin to add lambdas and partial application
{Pre}res:T{Post}
is valid modulo the Theory of Pointers. For which, you should find or define the Theory of Pointers. Similar to howa[i] = 1; j = i; a[j] = 2
should result ina[i] = 2
. A Hoare triple for this would be provable modulo the Theory of Arrays. $\endgroup$i:var int=0;f=()->{i++};/*some other code...*/;f()
In this case the runtime is creating a funpointer+pointer to &i,without taking the explicit address of i $\endgroup$