Skip to content

Instantly share code, notes, and snippets.

@andrevidela
Last active January 7, 2019 14:39
Show Gist options
  • Save andrevidela/8ec80d1a0afe697f021902feb2964aa6 to your computer and use it in GitHub Desktop.
Save andrevidela/8ec80d1a0afe697f021902feb2964aa6 to your computer and use it in GitHub Desktop.
struct Quadratic<A> {
let x²: A
let x: A
let c: A
}
extension Quadratic: Equatable where A: Equatable {}
extension Linear: FancyMult where A: Additive, A: Multiplicative {
typealias FancyVal = Quadratic<A>
static func ** (lhs: Linear<A>, rhs: Linear<A>) -> Quadratic<A> {
return Quadratic(x²: lhs.x * rhs.x,
x: lhs.x * rhs.c + lhs.c * rhs.x,
c: lhs.c * rhs.c)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment