Skip to content

Instantly share code, notes, and snippets.

@afsalthaj
Last active April 17, 2020 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afsalthaj/e12114d44b77bc48ff911114c9ce50ab to your computer and use it in GitHub Desktop.
Save afsalthaj/e12114d44b77bc48ff911114c9ce50ab to your computer and use it in GitHub Desktop.
trait Equal[-A] extends EqualLaws[A] {
def equal(a: A, b: A): Boolean
}
object Equal {
implicit val equalInt: Equal[Int] = new Equal[Int] {
def equal(a: Int, b: Int) = a == b
}
}
trait Monoid[A] extends MonoidLaws[A] {
def zero: A
def append(a: A, b: A): A
}
object Monoid {
implicit val monoidInt: Monoid[Int] = new Monoid[Int] {
def zero = 0
def append(a: Int, b: Int) = a + b
}
}
trait Foo {
type MyType
def get: MyType
}
val foo: Foo = new Foo {
type MyType = Int
def get: MyType = 1
}
val int: Int = foo.get
// compile time error. Scala doesn't the foo: Foo hold an Int, but we know it is definitely an Int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment