Skip to content

Instantly share code, notes, and snippets.

@pzel
Last active June 7, 2018 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pzel/b0033529a2ef7a7197179423d7e144f9 to your computer and use it in GitHub Desktop.
Save pzel/b0033529a2ef7a7197179423d7e144f9 to your computer and use it in GitHub Desktop.
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