Skip to content

Instantly share code, notes, and snippets.

@aripiprazole
Created August 21, 2022 00:59
Show Gist options
  • Save aripiprazole/bde22961036a4b26d7c59680d099818c to your computer and use it in GitHub Desktop.
Save aripiprazole/bde22961036a4b26d7c59680d099818c to your computer and use it in GitHub Desktop.
package ekko.tree
/**
* Type schemes are used to describe qualified types.
* Each TGen that appears in [qual] represents a generic that the kind is given
* by `[kinds] !! n`.
*/
data class Scheme(val kinds: List<Kind>, val qual: Qual<Typ>) {
companion object {
fun forall(vararg args: Kind) = fun(qual: Qual<Typ>): Scheme {
return Scheme(args.toList(), qual)
}
}
override fun toString(): String = when {
kinds.isEmpty() -> qual.toString()
else -> {
val kinds = kinds.mapIndexed { index, kind ->
"('${letters.elementAt(index)} : $kind)"
}
"forall $kinds. $qual"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment