Last active
June 7, 2018 07:55
-
-
Save pzel/b0033529a2ef7a7197179423d7e144f9 to your computer and use it in GitHub Desktop.
This file contains 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
class Maybe[A : Equatable[A] val] is Equatable[Maybe[A]] | |
let v : (A val | None) | |
new val create(thing: A) => v = thing | |
new val empty() => v = None | |
fun eq(that: box->Maybe[A]): Bool => | |
match (this.v, that.v) | |
| (let v' : A, let v'' : A) => v' == v'' | |
| (let n' : None, let n'' : None) => true | |
| (_, _) => false | |
end | |
actor Main | |
new create(env: Env) => | |
let full1 = Maybe[String]("hello") | |
let full2 = Maybe[String]("hello") | |
let full3 = Maybe[String]("world") | |
let empty1 = Maybe[String].empty() | |
let empty2 = Maybe[String].empty() | |
env.out.print((full1 == empty1).string()) //f | |
env.out.print((full1 == full2).string()) //t | |
env.out.print((full1 == full3).string()) //f | |
env.out.print((empty1 == empty2).string()) //t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment