Created
July 17, 2011 22:26
-
-
Save Villane/1088163 to your computer and use it in GitHub Desktop.
Klang: Classes + some math syntax experiments
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
class Vector2 { | |
data (x: Double, y: Double) | |
// other methods skipped | |
def length() = √(x² + y²) | |
alias |…| = length | |
} | |
def computeVectorLength(): Double = { | |
val v1 := Vector2(1, 1) | |
val v2 := Vector2(2, 3) | |
// enclosing method call syntax | |
// | v1 + v2 | == (v1 + v2).|…| | |
| v1 + v2 | | |
} | |
def main() = computeVectorLength().toInt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment