summaryrefslogtreecommitdiff
path: root/Jennisys/examples/oopsla12/List.jen
blob: 10a700508820cfb619ab27d5004df28c6a319bfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
interface List[T] {
  var list: seq[T]
  invariant |list| > 0

  constructor Singleton(t: T)
    list := [t]
  constructor Dupleton(p: T, q: T)
    list := [p q]
  method Elems() returns (ret: seq[T])
    ret := list
  method Get(idx: int) returns (ret: T)
    requires 0 <= idx && idx < |list|
    ret := list[idx]
  method Find(n: T) returns (ret: bool)
    ret := n in list
  method Size() returns (ret: int)
    ret := |list|
}
    
datamodel List[T] {    
  var data: T
  var next: List[T]

  frame next
  
  invariant
    next = null  ==> list = [data]
    next != null ==> list = [data] + next.list
}