Open
Description
In the following, valueOf
extracts a value from a monad ('a M -> 'a
). This is possible, for example, in a writer monad. In something like the option monad, you'd have SOME xxxx = m1
as the precondition to the equality on fm1
and fm2
.
val bind_cong = store_thm(
"bind_cong[defncong]",
``!m1 m2 fm1 fm2. (m1 = m2) /\ (!xxxx. xxxx = valueOf m1 ==> fm1 xxxx = fm2 xxxx) ==>
(bind m1 fm1 = bind m2 fm2)``,
rw[bind_def, valueOf_def] >>
Cases_on `m1` >>
Cases_on `r` >>
fs[]);
Now, using xxxx
below causes an error:
val fooM_def = Define`
fooM b =
do
if b = 0 then return 0
else do
(* no problem if xxxx is replaced by x *)
xxxx <- incM b;
y <- decM b;
fooM y;
od
od
`;
Discovered by Joseph Chan.