gop icon indicating copy to clipboard operation
gop copied to clipboard

Introduce builtin function: type

Open xushiwei opened this issue 5 years ago • 3 comments

In Go, we use reflect.TypeOf to get type of a value:

tyInt := reflect.TypeOf(int(0))
tyEmptyInterface := reflect.TypeOf((*interface{})(nil)).Elem() // no easy way to get an interface type

We may can introduce a type function to simplify it:

tyInt := type(int)
tyEmptyInterface := type(interface{})

xushiwei avatar Aug 17 '20 01:08 xushiwei

mayb be typeOf is an alternate choice. But I'm not very sure about this feature, it seems not very necessary.

JessonChan avatar Aug 20 '20 12:08 JessonChan

we can move this faction to another lib package, like "reflects".

JessonChan avatar Aug 21 '20 01:08 JessonChan

we can move this faction to another lib package, like "reflects".

Because we use types as parameters, it is not a normal function. It has to be a builtin function like new.

xushiwei avatar Aug 22 '20 02:08 xushiwei