Skip to content

Conversation

@mattisboeckle
Copy link
Contributor

@mattisboeckle mattisboeckle commented May 26, 2025

Aims to implement monomorphization for effekt.

  • Simple polymorphism
  • Functions with multiple polymorphic types
  • Different orders of types
  • Polymorphic data types
  • Polymorphic effects
  • Local polymorphic functions

The following programs have been used to (manually) test the implementation and should give an overview of what already works.

Simple polymorphic functions

def a[A](in: A) = { in }
def b[B](in: B): B = { a(in) }
def c[C](in: C): C = { b(in) }
def d[D](in: D): D = { c(in) }

def main() = {
  println(a(1))
  println(d("32"))
}

Multiple type arguments + switching the order of types

def f[C, D](in: C, in2: D) = in
def g[A, B](in: A, in2: B) = { f[B, A](in2, in) }
def main() = {
  println(g(3, "3"))
  println(g('c', false))
}

Polymorphic data types

type Maybe[A] {
  Nothing()
  Just(x: A)
}

def f[T](a: T): Maybe[T] = Just(a)

def main() = {
  val a = Just[Int](5)
  val b = Nothing[Char]()
  f(5)
  ()
}

Polymorphic effects

effect yield[A](x: A): Unit

def f() = {
  do yield[Int](123)
  do yield[String]("test")
}

def main() = {
  try {
    f()
  } with yield[Int] {
    x => println(x)
      resume(())
      resume(())
  } with yield[String] {
    x => println(x)
    resume(())
  }
  ()
}

@jiribenes jiribenes added the experiment Experimental branch, do not merge! label Jun 17, 2025
@mattisboeckle mattisboeckle force-pushed the mono branch 2 times, most recently from 1f90ac7 to a4439d5 Compare August 28, 2025 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experiment Experimental branch, do not merge!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants