Skip to content

Instantly share code, notes, and snippets.

@griotspeak
Last active May 28, 2016 23:03
Show Gist options
  • Save griotspeak/f0f3480cb6569b5e5ad9aff761bb996f to your computer and use it in GitHub Desktop.
Save griotspeak/f0f3480cb6569b5e5ad9aff761bb996f to your computer and use it in GitHub Desktop.
Wish I could tell the compiler to just use Expression
struct Expression : IntegerLiteralConvertible {
let value: Int
init(integerLiteral value: Int) {
self.value = value
}
}
struct Subexpression : IntegerLiteralConvertible {
let value: Int
init(integerLiteral value: Int) {
self.value = value
}
}
func * (lhs: Expression, rhs: Expression) -> Expression {
return Expression(integerLiteral: lhs.value * rhs.value)
}
func * (lhs: Subexpression, rhs: Expression) -> Expression {
return Expression(integerLiteral: lhs.value * rhs.value)
}
func * (lhs: Expression, rhs: Subexpression) -> Expression {
return Expression(integerLiteral: lhs.value * rhs.value)
}
typealias DefaultIntegerType = Expression
let foo: Expression = 3*((4 * 3) as Expression)
let bar: Expression = 4 * 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment