package main

import "fmt"

// section: base
type Distance float64

func (d Distance) String() string {
	return fmt.Sprintf("%.2f meters", d)
}

// section: base

// section: derived
// Creating a new type based on Distance
type Height Distance

// section: derived

func main() {
	// section: main
	var d Distance = 100.5
	fmt.Println(d.String()) // Works! Distance has String method

	var h Height = 180.0
	// h.String() // ERROR! Height does NOT have String method
	// Methods do NOT promote from Distance to Height

	// You must convert to Distance explicitly
	fmt.Println(Distance(h).String()) // Works with conversion
	// section: main
}

/*
// section: output
$ go run main.go
100.50 meters
180.00 meters
// section: output
*/
