FAQ
Can you still find that post?

Thanks

On Fri, Jul 26, 2013 at 4:07 PM, Michael Jones wrote:

I proposed discriminated unions way back and there was no interest. My
approach was to use a type switch to access them.

On Fri, Jul 26, 2013 at 8:00 AM, peterGo wrote:

Jackie,

As a practical matter, in Go, the solution is likely to be along the
following lines:

package main

import (
"fmt"
"math"
)

func IMax(x, y int64) int64 {
if x > y {
return x
}
return y
}

func IMin(x, y int64) int64 {
if x < y {
return x
}
return y
}

func FMax(x, y float64) float64 {
return math.Max(x, y)
}

func FMin(x, y float64) float64 {
return math.Min(x, y)

}

func main() {
var a int = 1
var b float32 = 2.718
fmt.Println(FMax(float64(a), float64(b)))
var aa uint8 = 8
var bb int32 = 32
fmt.Println(IMax(int64(aa), int64(bb)))

}

Peter
On Friday, July 26, 2013 5:21:55 AM UTC-4, Jackie wrote:

Hi fellow gophers,

Sorry if I sound very ignorant, I'm not a full time developer. I'm sure
somebody must already thought about this. But can we do this:

type Number union {
int
float32
}

func (n Number) Max(m Number) Number {
if n.(type) == int && m.(type) == int{
if n.(int) > m.(int) {
return n
}
return m
}
if float32(n) > float32(m) {
return n
}
return m
}

func main() {
var a int = 1
var b float32 = 2
fmt.Println(Number(a).Max(b))
}

Although it's not very clean, but I think it should have compile time
checks?
--
Jackie
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael T. Jones | Chief Technology Advocate | mtj@google.com | +1
650-335-5765

--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jackie

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 9 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 26, '13 at 9:22a
activeJul 26, '13 at 6:32p
posts9
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase