Last active
April 17, 2020 05:21
-
-
Save afsalthaj/e12114d44b77bc48ff911114c9ce50ab 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
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