Skip to content

Instantly share code, notes, and snippets.

@runarorama
Created March 11, 2012 15:52
Show Gist options
  • Save runarorama/2016899 to your computer and use it in GitHub Desktop.
Save runarorama/2016899 to your computer and use it in GitHub Desktop.
Perfect binary trees
object Perfect {
sealed trait Perfect[+A] {
// TODO: Try to implement flatMap.
// Hint: It can't be done. Why?
}
case class Empty extends Perfect[Nothing]
case class Node[+A](head: A, tail: Perfect[Perfect[A]]) extends Perfect[A]
sealed trait Square[+A]
case class Zero[+A](a: A) extends Square[A]
case class Succ[+A](succ: Square[(A, A)]) extends Square[A]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment