This file contains 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
// Aspect interface for combinator | |
interface Aspect { | |
operator fun <R> invoke(block: () -> R): R | |
} | |
// Aspect combinator | |
operator fun Aspect.plus(other: Aspect) = object : Aspect { | |
override fun <R> invoke(block: () -> R): R = | |
this@plus { | |
other { |
This file contains 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
// Basic setup | |
interface Exp | |
data class Lit(val x: Int): Exp | |
data class Add(val x: Exp, val y: Exp): Exp | |
interface IntAlg<A> | |
{ | |
fun lit(x: Int): A | |
fun add(x: A, y: A): A |