Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dafny – Functions without bodies

According to this answer I found (https://stackoverflow.com/a/47005291/13083263), we are able to define functions without code. I.e., dafny would simply use the pre and pos conditions for verification.

My question is: how can one do that?

For instance, the following code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function test(n: nat): (m: nat)
   ensures m == n+1

Gets me the error

Function _module._default.test has no body

>Solution :

A function defined without a body can be only be used for verification. For example, it could be called from requires / ensures elements or ghost code.

One option is to define a function with the {: extern} attribute (see here), and then provide a native implementation for it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading