Skip to content

Instantly share code, notes, and snippets.

@halcat0x15a
Created January 31, 2012 16:58
Show Gist options
  • Save halcat0x15a/1711578 to your computer and use it in GitHub Desktop.
Save halcat0x15a/1711578 to your computer and use it in GitHub Desktop.
SLisp
sealed trait SList {
type Self <: SList
type Function[A]
def apply[A](f: Function[A]): A
def ::[A](a: A) = SCons(a, this.asInstanceOf[Self])
}
case object SNil extends SList {
type Self = SNil.type
type Function[A] = A
def apply[A](f: Function[A]) = f
}
case class SCons[H, T <: SList](head: H, tail: T) extends SList {
type Self = SCons[H, T]
type Function[A] = H => tail.Function[A]
def apply[A](f: Function[A]) = tail[A](f(head))
def ::[A](f: Function[A]): A = apply[A](f)
}
((_: Int) + 10) :: 10 :: SNil
((_: Int) + (_: Int)).curried :: 10 :: 10 :: SNil
((_: Int) + (_: Int)).curried :: (((_: Int) + 10) :: 10 :: SNil) :: 10 :: SNil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment