Skip to content

Instantly share code, notes, and snippets.

@drexin
Created June 3, 2014 06:36
Show Gist options
  • Save drexin/e3022674f6ddf6fdb65f to your computer and use it in GitHub Desktop.
Save drexin/e3022674f6ddf6fdb65f to your computer and use it in GitHub Desktop.
protocol Monoid {
func unit() -> Self
func append(b: Self) -> Self
}
operator infix |+| { associativity left precedence 140 }
func |+|<A: Monoid>(a: A, b: A) -> A {
return a.append(b)
}
extension Int: Monoid {
func unit() -> Int { return 0 }
func append(b: Int) -> Int {
return self + b
}
}
println("2 |+| 3 = \(2 |+| 3)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment