Skip to content

Instantly share code, notes, and snippets.

@raichoo
Created October 13, 2011 12:47
Show Gist options
  • Save raichoo/1284154 to your computer and use it in GitHub Desktop.
Save raichoo/1284154 to your computer and use it in GitHub Desktop.
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))
}
}
@raichoo
Copy link
Author

raichoo commented Jul 17, 2013

Looking back. Zero only makes sense in combination with an operation. Scalaz also corrected this.
Zero as a typeclass does not make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment