Created
March 5, 2022 18:32
-
-
Save lemmy/22c7d1a3f463d38fb552d51b6c736dcb to your computer and use it in GitHub Desktop.
FoldSort.tla
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
No annotation found for Frob$1. Make sure that you've put one in front of Frob$1. E@18:30:44.591 | |
----- MODULE FoldSort ----- | |
EXTENDS Integers, Sequences, Apalache | |
\* @type: (Seq(Int), (a => Bool)) => Seq(Int); | |
FilterSeq(seq, cmp(_)) == | |
LET \* @type: (Seq(Int), Int) => Seq(Int); | |
Frob(acc, e) == IF cmp(e) THEN acc \o <<e>> ELSE acc | |
IN FoldSeq(Frob, <<>>, seq) | |
\* @type: (Seq(Int), Int) => Seq(Int); | |
SortedSeq(sorted, e) == | |
LET \* @type: Int => Bool; | |
Gt(a) == a > e | |
\* @type: Int => Bool; | |
Lt(a) == a < e | |
IN FilterSeq(sorted, Lt) \o <<e>> \o FilterSeq(sorted, Gt) | |
\* @type: (Seq(Int), Seq(Int)) => Seq(Int); | |
Sort(s1, s2) == | |
FoldSeq(SortedSeq, <<>>, s1 \o s2) | |
===== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment