Skip to content

Instantly share code, notes, and snippets.

@drexin
Created June 3, 2014 06:36
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 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