From 8b1792f861925483c1e3c46da139302aa793302f Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Mon, 10 Jun 2024 00:05:23 +0200 Subject: [PATCH] type wranging --- f.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/f.go b/f.go index fad6337..edffb0c 100644 --- a/f.go +++ b/f.go @@ -213,10 +213,11 @@ func prettyPrintLognormal(low float64, high float64) { } func prettyPrintDist(dist Dist) { - if dist.Type() == "Lognormal" { - prettyPrintLognormal(dist.low, dist.high) - } else { - fmt.Printf("%v", dist) + switch v := dist.(type) { + case Lognormal: + prettyPrintLognormal(v.low, v.high) + default: + fmt.Printf("%v", v) } } @@ -228,7 +229,8 @@ func main() { fmt.Printf("%v\n", x) reader := bufio.NewReader(os.Stdin) - init_dist := Dist{Type: "Lognormal", Lognormal: Lognormal{low: 1, high: 1}, Samples: nil} // Could also just be a scalar + var init_dist Dist + init_dist = Lognormal{low: 1, high: 1} old_dist := init_dist vars := make(map[string]Dist) // Could eventually be a more complex struct with: