effekt-lang / effekt

A research language with effect handlers and lightweight effect polymorphism

Home Page:https://effekt-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JS backend: Array.toList drops first element

marzipankaiser opened this issue · comments

Executing .toList on an array drops the first element.

Example

For the program:

import mutable/array

def main() = {
  val array = arrayFromList([1,2,3]);
  println(array.toList)
}

we get the output:

Cons(2, Cons(3, Nil()))

Problem seems to be the > in the array-to-list conversion here, should be >=:

def toList[T](arr: Array[T]): List[T] = {
var i = arr.size - 1;
var l = Nil[T]()
while (i > 0) {
l = Cons(unsafeGet(arr, i), l)
i = i - 1
}
l
}