Last active
January 7, 2019 14:40
-
-
Save andrevidela/192bb551bb80919f3961d6c15b718db3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
struct Linear<A> { | |
let x: A | |
let c: A // c stands for 'constant', it's the constant factor to the linear function | |
} | |
extension Linear: CustomStringConvertible where A: CustomStringConvertible { | |
var description: String { return "f(x) = \(x)x + \(c)" } | |
} | |
extension Linear: Equatable where A: Equatable {} | |
extension Linear: TwoDimensions { | |
typealias ComponentVal = A | |
static func make2D(_ fst: A, _ snd: A) -> Linear { | |
return Linear(x: fst, c: snd) | |
} | |
var fst: A { return x } | |
var snd: A { return c } | |
} | |
extension Linear: Additive where A: Additive {} | |
extension Linear: Scalar where A: Multiplicative { typealias ScalarVal = A } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment