Alley Stoughton
Alley Stoughton

Reputation: 41

how are sequences intended to be represented in Dafny?

Sequences in Dafny are an immutable type, so from a verification point of view, it doesn't matter how they are represented at runtime. But as functional programmers know, it's normal to represent lists in a functional language (under the hood, in a way the programmer can't manipulate) as linked lists, so that taking the tail of a list is constant time (and involves no storage allocation), and so that list concatenation reallocates the cells of the left argument, but just uses the reference to the right argument.

Is anything written down about how sequences are intended to be represented in Dafny implementations? Again, this is only an issue if one wants to actually run Dafny programs.

Upvotes: 2

Views: 183

Answers (1)

smithjonesjr
smithjonesjr

Reputation: 981

In all of Dafny's current backends, sequences (and arrays for that matter) are represented by an array or vector type.

In general, you can check the Runtime source files to see how Dafny implements anything "under the hood": https://github.com/dafny-lang/dafny/tree/master/Source/DafnyRuntime

Meanwhile, if you want to use a linked list, you could make your own linked list datatype:

datatype List<V> = Cons(v: V, tail: List<V>) | Nil

Upvotes: 4

Related Questions