Skip to content

Instantly share code, notes, and snippets.

@Villane
Created July 17, 2011 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Villane/1088163 to your computer and use it in GitHub Desktop.
Save Villane/1088163 to your computer and use it in GitHub Desktop.
Klang: Classes + some math syntax experiments
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