Partial solution not working: http://rise4fun.com/Dafny/qrCa7 code: // Naive implementation module naive { datatype buf = Cons(h: int, xs: seq) function empty(h: int):buf requires h >= 1 { buf.Cons(h, []) } function take(n:int, xs:seq):seq requires 0 <= n { if n > |xs| then xs[..|xs|] else xs[..n] } function add(x: T, b: buf):buf { Cons(b.h, [x] + b.xs) } function get(b: buf):seq requires b.h >= 0 { take(b.h, b.xs) } } module caterpillar { import naive class buf { ghost var rep : naive.buf; var h: int; var xs: array; var xs_len: int; var ys: array; } predicate valid(b: buf) reads b, b.xs, b.ys { b != null && b.xs != null && b.ys != null && 0 <= b.xs_len < b.h && b.xs.Length >= b.h && (b.xs[..]+b.ys[..])[..min(b.h, b.xs.Length + b.ys.Length)] == naive.get(b.rep) } function method min(a: int, b:int):int { if a < b then a else b } method get(b:buf) returns (r:seq) requires valid(b) ensures naive.get(b.rep) == r { r := (b.xs[..]+b.ys[..])[..min(b.h, b.xs.Length + b.ys.Length)]; } method empty(h: int) returns (r:buf) requires h >= 1; ensures valid(r); { r := new buf; r.rep := naive.empty(h); r.h := h; r.xs := new T[h]; r.xs_len := 0; r.ys := new T[0]; } method add(x: T, b: buf) requires valid(b); ensures valid(b) && naive.add(x, old(b.rep)) == b.rep modifies b modifies b.xs { if b.xs_len == b.h - 1 { b.xs[b.xs_len] := x; b.ys := b.xs; b.xs_len := 0; b.xs := new T[b.h]; b.rep := naive.add(x, b.rep); } else { b.xs[b.xs_len] := x; b.xs_len := b.xs_len + 1; b.rep := naive.add(x, b.rep); } } }