On Fri, Oct 20, 2023 at 1:07 PM Nurahmadie Nurahmadie
wrote:
> This statement doesn't feel right to me, one can always do `type NewType
> struct{}` to create genuinely new types, but if you do `type String
> string`, for example, surely you expect String to has `string` value, hence
> there will
On Fri, 20 Oct 2023 at 16:58, 'Axel Wagner' via golang-nuts <
golang-nuts@googlegroups.com> wrote:
> FWIW I think what OP is ultimately asking about is some form of nominal
> subtyping. When they say "automatic upcasting", they refer (I believe) to
> what Go calls "assignability", which is in esse
FWIW I think what OP is ultimately asking about is some form of nominal
subtyping. When they say "automatic upcasting", they refer (I believe) to
what Go calls "assignability", which is in essence a subtype relationship.
So they want to be able to define a new type, that is a subtype of an
existing
On Oct 19, 2023, at 9:02 PM, Nurahmadie Nurahmadie wrote:
>
> Is it not possible to have both _auto_ downcasting and new method binding to
> work in Go?
What you are suggesting may make things more *convenient* but
at the same time the potential for accidental mistakes goes
up. The key is find
> Personally, I find "why" questions suspicious. They are usually thinly
> disguised requests to change the existing behavior. And that appears to be
> the case for this discussion.
>
No, that's not to be the case, I do imagining the change, but am not
thinking of requesting any change, I know th
On Thu, Oct 19, 2023 at 9:56 PM Nurahmadie Nurahmadie
wrote:
>
>> You have changed the question. You are no longer asking about defining
>> methods on a type derived from a primitive type. Non-aliased types are
>> deliberately distinct types that cannot be "auto downcast" or "auto
>> upcast". Arg
On Fri, 2023-10-20 at 11:56 +0700, Nurahmadie Nurahmadie wrote:
> why is there no, type coercion, as you said, that allow the new type
> to be acknowledged as its underlying type? which will not be a
> question if otherwise Go has mechanism to allow methods to be
> attached to foreign types.
There
>
>
> You have changed the question. You are no longer asking about defining
> methods on a type derived from a primitive type. Non-aliased types are
> deliberately distinct types that cannot be "auto downcast" or "auto
> upcast". Arguably the biggest flaw of the C language was its automatic type
>
On Thu, Oct 19, 2023 at 9:03 PM Nurahmadie Nurahmadie
wrote:
> Adding methods to a primitive type, or more generally adding methods
>> to a type defined in a different package, would cause different
>> packages to behave differently depending on whether they see the
>> methods. That would be con
> Adding methods to a primitive type, or more generally adding methods
> to a type defined in a different package, would cause different
> packages to behave differently depending on whether they see the
> methods. That would be confusing. It would meant that type
> assertions would sometimes suc
On Thu, Oct 19, 2023 at 6:18 PM Nurahmadie Nurahmadie
wrote:
>
> There are two ways to enable this, which are worth discussing further as of
> why Go decided to behave this way.
>
> To use type alias as mentioned before `type MatrixF64 = Matrix[float64]`,
> this is generally works but unfortunat
On Fri, 20 Oct 2023 at 07:51, Ian Lance Taylor wrote:
> On Thu, Oct 19, 2023 at 5:14 PM Jason E. Aten wrote:
> >
> > Analogous to
> >
> > type IntSlice []int
> >
> > func (p IntSlice) Len() int { return len(p) }
> > func (p IntSlice) Less(i, j int) bool { return p[i].val < p[j].val }
> > func (p
On Thu, Oct 19, 2023 at 5:14 PM Jason E. Aten wrote:
>
> Analogous to
>
> type IntSlice []int
>
> func (p IntSlice) Len() int { return len(p) }
> func (p IntSlice) Less(i, j int) bool { return p[i].val < p[j].val }
> func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
>
> and then calling
Analogous to
type IntSlice []int
func (p IntSlice) Len() int { return len(p) }
func (p IntSlice) Less(i, j int) bool { return p[i].val < p[j].val }
func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
and then calling sort.Sort() on an IntSlice, I figured I
could create a type that is a
14 matches
Mail list logo