summaryrefslogtreecommitdiff
path: root/Test/hofs
diff options
context:
space:
mode:
authorGravatar Dan Rosén <danr@chalmers.se>2014-08-18 13:24:57 -0700
committerGravatar Dan Rosén <danr@chalmers.se>2014-08-18 13:24:57 -0700
commit5e7d03fba113642aa1d6b181a854c684c740979e (patch)
tree11043399075689c198e6c44dcafb868445c0dc48 /Test/hofs
parent2ead070c052fb5f506f188571e0e1bef900af9d4 (diff)
Consider lambdas literals + create literal axioms when an argument is a function
Diffstat (limited to 'Test/hofs')
-rw-r--r--Test/hofs/Fold.dfy30
-rw-r--r--Test/hofs/Fold.dfy.expect6
-rw-r--r--Test/hofs/TreeMapSimple.dfy8
-rw-r--r--Test/hofs/TreeMapSimple.dfy.expect7
4 files changed, 48 insertions, 3 deletions
diff --git a/Test/hofs/Fold.dfy b/Test/hofs/Fold.dfy
new file mode 100644
index 00000000..df7d0126
--- /dev/null
+++ b/Test/hofs/Fold.dfy
@@ -0,0 +1,30 @@
+// RUN: %dafny /compile:3 "%s" > "%t"
+// RUN: %diff "%s.expect" "%t"
+
+datatype List = Nil | Cons(A,List<A>);
+
+datatype Expr = Add(List<Expr>) | Mul(List<Expr>) | Lit(int);
+
+function method Eval(e : Expr): int
+{
+ match e
+ case Add(es) => Fold(es,0,(e,v) requires e < es => Eval(e) + v)
+ case Mul(es) => Fold(es,1,(e,v) requires e < es => Eval(e) * v)
+ case Lit(i) => i
+}
+
+function method Fold(xs : List<A>, unit : B, f : (A,B) -> B): B
+ reads f.reads;
+ requires forall x : A, y: B :: x < xs ==> f.requires(x,y);
+{
+ match xs
+ case Nil => unit
+ case Cons(x,xs) => f(x,Fold(xs,unit,f))
+}
+
+method Main() {
+ var two := Lit(2);
+ var add := (x,y) => Add(Cons(x,Cons(y,Nil)));
+ assert Eval(add(two,two)) == 4;
+ print "3 = ", Eval(add(Lit(1),two)), "\n";
+}
diff --git a/Test/hofs/Fold.dfy.expect b/Test/hofs/Fold.dfy.expect
new file mode 100644
index 00000000..d76e85f9
--- /dev/null
+++ b/Test/hofs/Fold.dfy.expect
@@ -0,0 +1,6 @@
+
+Dafny program verifier finished with 4 verified, 0 errors
+Program compiled successfully
+Running...
+
+3 = 3
diff --git a/Test/hofs/TreeMapSimple.dfy b/Test/hofs/TreeMapSimple.dfy
index e717b096..3c70840e 100644
--- a/Test/hofs/TreeMapSimple.dfy
+++ b/Test/hofs/TreeMapSimple.dfy
@@ -1,4 +1,4 @@
-// RUN: %dafny "%s" > "%t"
+// RUN: %dafny /compile:3 "%s" > "%t"
// RUN: %diff "%s.expect" "%t"
datatype List<A> = Nil | Cons(head: A,tail: List<A>);
@@ -47,3 +47,9 @@ function method TMap(t0 : Tree<A>, f : A -> B) : Tree<B>
=> TMap(t,f)))
}
+method Main()
+{
+ var t := TMap(Branch(1,Cons(Branch(2,Nil),Nil)), x requires x != 0 => 100 / x);
+ assert t == Branch(100,Cons(Branch(50,Nil),Nil));
+ print t, "\n";
+}
diff --git a/Test/hofs/TreeMapSimple.dfy.expect b/Test/hofs/TreeMapSimple.dfy.expect
index f523ef5d..3b59a2e3 100644
--- a/Test/hofs/TreeMapSimple.dfy.expect
+++ b/Test/hofs/TreeMapSimple.dfy.expect
@@ -1,3 +1,6 @@
-Dafny program verifier finished with 5 verified, 0 errors
-Compiled assembly into TreeMapSimple.dll
+Dafny program verifier finished with 7 verified, 0 errors
+Program compiled successfully
+Running...
+
+Tree.Branch(100, List.Cons(Tree.Branch(50, List.Nil), List.Nil))