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