Tin

Examples · learn/05-structs · 108 of 339

nested

examples/learn/05-structs/nested.tintin run examples/learn/05-structs/nested.tin
type Point = { x: float, y: float }
type Line = { from: Point, to: Point }

fn length(l: Line): float {
  let dx = l.to.x - l.from.x
  let dy = l.to.y - l.from.y
  sqrt(dx * dx + dy * dy)
}

fn main() {
  let line = Line { from: Point { x: 0.0, y: 0.0 }, to: Point { x: 3.0, y: 4.0 } }
  print(length(line))
}