Skip to content
Snippets Groups Projects
Commit c12d6081 authored by Régis Blanc's avatar Régis Blanc
Browse files

update List

parent f488cec4
No related branches found
No related tags found
No related merge requests found
import leon.Utils._ import leon.Utils._
import leon.Annotations._
object List { object List {
...@@ -6,9 +7,14 @@ object List { ...@@ -6,9 +7,14 @@ object List {
case class Cons(head: Int, tail: List) extends List case class Cons(head: Int, tail: List) extends List
case class Nil() extends List case class Nil() extends List
def size(l: List): Int = waypoint(1, (l match { @main
case Cons(_, tail) => 1 + size(tail) def size(l: List): Int = (l match {
case Cons(_, tail) => sizeTail(tail, 1)
case Nil() => 0 case Nil() => 0
})) ensuring(_ >= 0) }) ensuring(_ >= 0)
def sizeTail(l2: List, acc: Int): Int = l2 match {
case Cons(_, tail) => sizeTail(tail, acc+1)
case Nil() => acc
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment