Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scala 3.5 migration #107

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
migration to 3.5
  • Loading branch information
samuelchassot committed Aug 23, 2024
commit 92534e3f5b6d2f0f4bc87cba0371ce8713a25944
4 changes: 2 additions & 2 deletions tutorials/dispenser/Dispenser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ object Dispenser {
List(b10,b10,b10,b10)),
coins = BigInt(0),
oneInserted=false)
val Some(s1) = r(s0, FirstCoin())
val Some(s2) = r(s1, SecondCoin(0,0))
val Some(s1) = r(s0, FirstCoin()): @unchecked
val Some(s2) = r(s1, SecondCoin(0,0)): @unchecked
List[(State,Action)]((s0, FirstCoin()), (s1, SecondCoin(0,0)), (s2, FirstCoin()))
}.ensuring(res => isTrace(res))

Expand Down
16 changes: 8 additions & 8 deletions tutorials/krakow2020/IntSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ sealed abstract class IntSet {
def incl(x: Int): IntSet = this match {
case Empty() => Node(Empty(),x,Empty())
case Node(left, elem, right) =>
if (x < elem) Node(left incl x, elem, right)
else if (x > elem) Node(left, elem, right incl x)
if (x < elem) Node(left.incl(x), elem, right)
else if (x > elem) Node(left, elem, right.incl(x))
else this
}
def contains(x: Int): Boolean = this match {
case Empty() => false
case Node(left, elem, right) =>
if (x < elem) left contains x
else if (x > elem) right contains x
if (x < elem) left.contains(x)
else if (x > elem) right.contains(x)
else true
}

def P1(x: Int): Boolean = {
true
}.ensuring(_ => !(Empty() contains x))
}.ensuring(_ => !(Empty().contains(x)))

def P2(s: IntSet, x: Int): Boolean = {
s match {
Expand All @@ -33,7 +33,7 @@ sealed abstract class IntSet {
else if (x > elem) P2(right, x)
else true
}
}.ensuring(_ => (s incl x) contains x)
}.ensuring(_ => (s.incl(x)).contains(x))

def P3(s: IntSet, x: Int, y: Int): Boolean = {
require(x != y)
Expand All @@ -44,11 +44,11 @@ sealed abstract class IntSet {
else if (x > elem) P3(right, x, y)
else true
}
}.ensuring(_ => ((s incl x) contains y)==(s contains y))
}.ensuring(_ => ((s.incl(x)).contains(y))==(s.contains(y)))

def union(other: IntSet): IntSet = this match {
case Empty() => other
case Node(left, x, right) =>
(left union (right union other)) incl x
(left.union(right.union(other))).incl(x)
}
}
18 changes: 9 additions & 9 deletions tutorials/krakow2020/IntSetInv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,36 @@ sealed abstract class IntSet {
def incl(x: Int): IntSet = { this match {
case Empty() => Node(Empty(),x,Empty())
case Node(left, elem, right) =>
if (x < elem) Node(left incl x, elem, right)
else if (x > elem) Node(left, elem, right incl x)
if (x < elem) Node(left.incl(x), elem, right)
else if (x > elem) Node(left, elem, right.incl(x))
else this
}}.ensuring(res => res.content == this.content ++ Set(x))

def contains(x: Int): Boolean = {this match {
case Empty() => false
case Node(left, elem, right) =>
if (x < elem) left contains x
else if (x > elem) right contains x
if (x < elem) left.contains(x)
else if (x > elem) right.contains(x)
else true
}}.ensuring(res => (res == (this.content.contains(x))))

def P1(x: Int): Unit =
().ensuring(_ => !(Empty().contains(x)))

def P2(s: IntSet, x: Int): Unit =
().ensuring(_ => (s incl x) contains x)
().ensuring(_ => (s.incl(x)).contains(x))

def P3(s: IntSet, x: Int, y: Int): Unit = {
require(x != y)
}.ensuring(_ => ((s incl x) contains y)==(s contains y))
}.ensuring(_ => ((s.incl(x)).contains(y))==(s.contains(y)))

def union(other: IntSet): IntSet = {this match {
case Empty() => other
case Node(left, x, right) =>
(left union (right union other)) incl x
(left.union(right.union(other))).incl(x)
}}.ensuring(res => res.content == this.content ++ other.content)

def P4(t1: IntSet, t2: IntSet, x: Int): Unit =
().ensuring(_ => ((t1 union t2) contains x)==
(t1 contains x) || (t2 contains x))
().ensuring(_ => ((t1.union(t2)).contains(x))==
(t1.contains(x)) || (t2.contains(x)))
}