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

Mini mutable set implementation with trait interface, as example and better understanding of ASTs #101

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
Next Next commit
Mini Set implementation to diagnose trait and laws or empty method
  • Loading branch information
samuelchassot committed Aug 6, 2024
commit e96990ce165c59a46399fe689e86ec4561e0d3fd
13 changes: 13 additions & 0 deletions modularity/MiniMutSet.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package modularity

import stainless.collection._
import stainless.lang._
import stainless.annotation._

object MiniMutableSet:

@mutable
final case class MiniMutSet[V](private var content: List[V]) extends MiniMutableSetInterface.MiniMutableSet[V]:
override def contains(v: V): Boolean = content.contains(v)
override def add(v: V): Unit = content = v :: content
end MiniMutableSet
26 changes: 26 additions & 0 deletions modularity/iMiniMutSet.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package modularity


import stainless.collection._
import stainless.lang._
import stainless.annotation._


object MiniMutableSetInterface:
@mutable
trait MiniMutableSet[V]:
@pure def contains(v: V): Boolean
def add(v: V): Unit = {
??? : Unit
}.ensuring(_ => contains(v))
end MiniMutableSet
end MiniMutableSetInterface


object MiniSetUsage:
import MiniMutableSetInterface._
def testMiniMutableSet(s: MiniMutableSet[BigInt]): Unit = {
s.add(1)
assert(s.contains(1))
}
end MiniSetUsage