koka-lang / koka

Koka language compiler and interpreter
http://koka-lang.org
Other
3.16k stars 151 forks source link

Problem with TRMC: This program fails to terminate #355

Closed TimWhiting closed 10 months ago

TimWhiting commented 10 months ago
fun splitBy(l: list<a>, i: int): div list<list<a>>
  val (a, b) = l.split(i)
  Cons(a, b.splitBy(i))

fun main()
  [0, 0, 0, 0].splitBy(2)
TimWhiting commented 10 months ago

Forgot to match on b. split returns nil as the second value when it reaches the end:

fun splitBy(l: list<a>, i: int): div list<list<a>>
  val (a, b) = l.split(i)
  match b
    Nil -> Cons(a, Nil)
    _ -> Cons(a, b.splitBy(i))