Skip to content

Commit

Permalink
cleaned up list benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
IR0NSIGHT committed Nov 6, 2023
1 parent 4ce6e86 commit be756fb
Showing 1 changed file with 22 additions and 69 deletions.
91 changes: 22 additions & 69 deletions examples/fasteffekt/list.effekt
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import examples/fasteffekt/benchmark


// class Element {
// constructor(v) {
// this.val = v;
// this.next = null;
// }
record Element (
value: Int, child: Option[Element]
)
Expand All @@ -15,13 +9,6 @@ def length(element: Option[Element]): Int =
case None() => return 0;
case Some(Element(value, child)) => return 1 + length(child)
}
// length() {
// if (this.next === null) {
// return 1;
// }
// return 1 + this.next.length();
// }
// }

def isShorterThan(x: Option[Element], y: Option[Element]): Boolean = {
var xTail:Option[Element] = x;
Expand All @@ -36,14 +23,6 @@ def isShorterThan(x: Option[Element], y: Option[Element]): Boolean = {
}
}
return bigger;

// while (yTail !== null) {
// if (xTail === null) { return true; }
// xTail = xTail.next;
// yTail = yTail.next;
// }
// return false;

}

def makeList(lenght: Int): Option[Element] = {
Expand All @@ -54,36 +33,31 @@ def makeList(lenght: Int): Option[Element] = {
}
}

//no idea what that function does.
def tail(x: Option[Element], y: Option[Element], z: Option[Element]): Option[Element] = {
if (y.isShorterThan(x)) {
(x,y,z) match {
case (Some(xx),Some(yy),Some(zz)) =>
//compiler KNOWS that xx,yy,zz are not None() => can access children.

//all children have type Option[Element]
val xChild = xx.child;
val yChild = yy.child;
val zChild = zz.child;

val xxx = tail(xChild, y, z);
val yyy = tail(yChild, z, x);
val zzz = tail(zChild, x, y);
tail(
xxx,
yyy,
zzz
)
case _ => panic("oh no!");
}
} else {
z;
//no idea what that function does.
def tail(x: Option[Element], y: Option[Element], z: Option[Element]): Option[Element] = {
if (y.isShorterThan(x)) {
(x,y,z) match {
case (Some(xx),Some(yy),Some(zz)) =>
val yChild : Option[Element] = yy.child;
val zChild : Option[Element] = zz.child;
val xChild : Option[Element] = xx.child;

val xxx: Option[Element] = tail(xChild, y, z);
val yyy: Option[Element] = tail(yChild, z, x);
val zzz: Option[Element] = tail(zChild, x, y);
tail(
xxx,
yyy,
zzz
)
case _ => panic("oh no!");
}
} else {
z;
}
}

def List() = {
println("run list benchmark");

def benchmark(): Int = {
val result =
tail(
Expand All @@ -94,7 +68,6 @@ def List() = {
length(result);
}



def verifyResult(result: Int): Boolean = {
return result == 10;
Expand All @@ -105,24 +78,4 @@ def List() = {

def main() = {
List();
}
// class List extends Benchmark {



// tail(x, y, z) {
// if (this.isShorterThan(y, x)) {
// return this.tail(
// this.tail(x.next, y, z),
// this.tail(y.next, z, x),
// this.tail(z.next, x, y)
// );
// }
// return z;
// }

// verifyResult(result) {
// return 10 === result;
// }
// }

}

0 comments on commit be756fb

Please sign in to comment.