-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'unstable' into ik/sequences1486-2
- Loading branch information
Showing
6 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--------------------------- MODULE Folds ----------------------------------- | ||
\*------ MODULE __rewire_folds_in_apalache ----------------------- | ||
(** | ||
* ^^^^^^^^^^^^^^^^^^^^^^ We have to call this module Folds in any | ||
* case, otherwise, SANY complains. | ||
* | ||
* This file contains alternative definitions for the operators defined in | ||
* Folds. Most importantly, we are adding type annotations. We also | ||
* define the Apalache-compatible behavior. | ||
* | ||
* These definitions are automatically rewired by the Apalache importer. | ||
* | ||
* Compare with the original definitions in Folds.tla: | ||
* | ||
* https://github.com/tlaplus/CommunityModules/blob/master/modules/Folds.tla | ||
*) | ||
|
||
EXTENDS __apalache_internal | ||
|
||
|
||
(** | ||
* Starting from base, apply op to f(x), for all x \in S, by choosing the set | ||
* elements with `choose`. If there are multiple ways for choosing an element, | ||
* op should be associative and commutative. Otherwise, the result may depend | ||
* on the concrete implementation of `choose`. | ||
* | ||
* FoldSet, a simpler version for sets is contained in FiniteSetsEx. | ||
* FoldFunction, a simpler version for functions is contained in Functions. | ||
* FoldSeq, a simpler version for sequences is contained in SequencesExt. | ||
* | ||
* Apalache (the model checker) does not support MapThenFoldSet. | ||
* However, we introduce this definition for the type checker. | ||
* | ||
* @type: ((a, b) => b, b, c => a, Set(c) => c, Set(c)) => b; | ||
*) | ||
MapThenFoldSet(op(_, _), base, f(_), choose(_), S) == | ||
__NotSupportedByModelChecker("MapThenFoldSet. Use FoldSet, FoldSeq, FoldFunction.") | ||
|
||
============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
------------------------ MODULE TestFolds ------------------------------------- | ||
(** | ||
* A test for the community module Folds. | ||
* Since our implementation calls __NotSupportedByModelChecker, | ||
* it is only useful to test it with a type checker. | ||
*) | ||
|
||
EXTENDS Folds | ||
|
||
Init == TRUE | ||
|
||
Next == TRUE | ||
|
||
Test1 == | ||
LET \* @type: Seq(Set(Str)); | ||
seq == <<{"a"}, {"b"}, {"c"}>> | ||
IN | ||
LET F(i) == seq[i] IN | ||
LET unite(S, T) == S \union T IN | ||
LET choose(S) == CHOOSE x \in S: TRUE IN | ||
MapThenFoldSet(unite, {}, F, choose, { 2, 3 }) = { "b", "c" } | ||
|
||
AllTests == | ||
Test1 | ||
|
||
=============================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters