Closed andricicezar closed 4 years ago
So the error Cezar wrote is from an old branch which I need to merge. Current F* fails with a mysterious:
(Error) Type annotation on parameter incompatible with the expected type; The solver found a (partial) counterexample, try to spell your proof in more detail or increase fuel/ifuel
which happens since incrs1'
elaborates roughly to
let incrs1 : (x:int) -> Pure int (x > 0) (fun y -> y = x + 1) = fun x -> x + 1
let incrs1' : int -> ML int =
export #(x:int -> Pure int (x > 0) (fun (y:int{y > x}) -> y = x + 1))
#(magic ())
incrs1
(ignore the magic, I added that since that part is not relevant)
For some reason the unifier is infering the type of incrs1
to have a refinement on y
in the condition, as shown above. That fails, since we expect a total function there. Not sure where this is coming up. It might be some weird interaction with the fix of #57, but in that case I would expect to see the refinement on y
being about x>0
, not y>x
.
I seem to have made a mistake when transcribing it. The refinement is indeed that x > 0
according to the precondition, due to the #57 fix, and this program can be fixed by modifying exportable_purearrow_spec
to be fully generic for all Pure
functions:
instance exportable_purearrow_spec t1 t2 (pre : t1 -> Type0) (post : (x:t1 -> _:t2{pre x} -> Type0))
(* ... as before *)
Naming the postcondition as in postcond
works since it ascribes the type to int
, instead of y:int{x > 0}
. This will also work by ascribing the type of y
in the postcondition of incrs2
:
let incrs2 : (x:int) -> Pure int (x > 0) (fun (y:int) -> y = x + 1) = fun x -> x + 1
let incrs2' : int -> ML int = export incrs2
@andricicezar : in the dm4a branch, the second solution (annotating y
) seems to work. Not the first one, but not sure why.
Another thing you can do is locally redefine Pure
without the trick for #57, so your postconditions do not have any refinement:
effect Pure (a:Type) (pre:Type0) (post: a->Type0) = Prims.Pure a pre post
Personally, I would personally the types, I feel this redefinition might get you in a tough corner at some point.
Closing.
I am cool with annotating the types. Thank you very much for looking into this!
I do not know how to describe this.
error: