This file contains hidden or 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
#include <stdio.h> | |
typedef struct _trampoline_data { | |
void(*callback)(struct _trampoline_data*); | |
void* parameters; | |
} trampoline_data; | |
void trampoline(trampoline_data* data) { | |
while(data->callback != NULL) | |
data->callback(data); |
This file contains hidden or 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
sealed trait Bounce[A] | |
case class Done[A](result: A) extends Bounce[A] | |
case class Call[A](thunk: () => Bounce[A]) extends Bounce[A] | |
def trampoline[A](bounce: Bounce[A]): A = bounce match { | |
case Call(thunk) => trampoline(thunk()) | |
case Done(x) => x | |
} | |
def factorial(n: Int, sum: BigInt): Bounce[BigInt] { |
This file contains hidden or 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
import java.math.BigInteger; | |
class Trampoline<T> | |
{ | |
public T get() { return null; } | |
public Trampoline<T> run() { return null; } | |
T execute() { | |
Trampoline<T> trampoline = this; |
NewerOlder