Created
February 17, 2011 20:19
-
-
Save oluies/832587 to your computer and use it in GitHub Desktop.
stree
This file contains hidden or 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
sealed abstract class Tree[A] | |
case class Leaf[A](elem : A) extends Tree[A] | |
case class Node[A](left : Tree[A], right : Tree[A]) extends Tree[A] | |
val t = Node(Leaf(11), Node(Leaf(13),Leaf(15) )) | |
def sum(t: Tree[Int]):Int = t match { | |
case Leaf(i) => i | |
case Node(l,r) => sum(l) + sum(r) | |
case _ => error("FUBAR tree") | |
} | |
println(sum(t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment