Created
October 13, 2011 12:47
-
-
Save raichoo/1284154 to your computer and use it in GitHub Desktop.
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
case object One | |
trait Zero[A] { | |
def zero: A | |
} | |
object Zero { | |
implicit val oneZero: Zero[One.type] = new Zero[One.type] { | |
def zero: One.type = One | |
} | |
} | |
trait Monoid[A] { | |
def mappend(a: A, b: A): A | |
def mzero: A | |
} | |
object Monoid { | |
implicit val oneMonoid: Monoid[One.type] = new Monoid[One.type] { | |
def mappend(a: One.type, b: One.type): One.type = One | |
def mzero: One.type = One | |
} | |
} | |
object Main { | |
def test[A](a: A)(implicit zero: Zero[A], | |
mon: Monoid[A], | |
ev: Zero[A] =:= Zero[One.type]) = mon.mappend(a, a) | |
def main(args: Array[String]) { | |
println(test(One)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking back. Zero only makes sense in combination with an operation. Scalaz also corrected this.
Zero as a typeclass does not make sense.