dafny

How to declare type in dafny which supports ordering


Dafny has following ways to declare type which supports equality.

T(==)

But is there way to specify type supports ordering (<, <=, >, >=) etc.?


Solution

  • Dafny doesn't support operator overloading. However, you can define your own predicates to support ordering on your data type. If you make it a module then you can abstract away the actual ordering comparison as well. Then later when you have a native type that supports those operators you can just supply the implementation of the operations as a module instance.

    There was a great blog post with an example, which now I can only find on the wayback machine here