Recursive functions are allowed. For instance, having defined functions to compute fibonacci numbers.

import swam._
import text._
import runtime._
import formats.DefaultFormatters._
import cats.effect._
import java.nio.file.Paths

val tcompiler = Compiler[IO]

val engine = Engine[IO]

def instantiate(p: String): Instance[IO] =
  (for {
    engine <- engine
    tcompiler <- tcompiler
    m <- engine.compile(tcompiler.stream(Paths.get(p), true))
    i <- m.instantiate
  } yield i).unsafeRunSync()

def time[T](t: => T): T = {
  val start = System.currentTimeMillis
  val res = t
  val end = System.currentTimeMillis
  println(s"Time: ${end - start}ms")
  res
}

val i = instantiate("fibo.wat")

val naive = i.exports.typed.function1[Long, Long]("naive").unsafeRunSync()
val clever = i.exports.typed.function1[Long, Long]("clever").unsafeRunSync()

This would result in:

time(naive(30).unsafeRunSync())
// Time: 12781ms
// res0: Long = 1346269L
time(clever(30).unsafeRunSync())
// Time: 2ms
// res1: Long = 1346269L