[go-nuts] Re: some interesting ideas: reuse package keyword to declare generics

2020-09-11 Thread Di gg
Still a mistake there. All "MyReader" uses should be "*MyReader".

On Friday, September 11, 2020 at 11:02:49 PM UTC-4 Di gg wrote:

> Sorry, the last 4 lines should be:
>
> rs = (MyReader string)(rb)
> _, _ = rs.Read(s)
> rb = (MyReader []byte)(rs)
> _, _ = rb.Read(bs)
>
> On Friday, September 11, 2020 at 11:00:12 PM UTC-4 Di gg wrote:
>
>> An example demostrating how to let Reader.Read support both string and 
>> []byte parameters.
>>
>> package readonlybytes[T] (
>> assert T.kind & (String | Slice)
>> )
>>
>> package Reader[T] (
>> assert readonlybytes[T]
>> ){
>> type Reader interface {
>> Read(bytes T)(n int, err error)
>> }
>> }
>>
>> package MyReader[T](
>> assert T.kind & (String | Slice)
>> ){
>> type MyReader struct{}
>>
>> type (r *MyReader) Read(s T)(int, error) {
>> return len(s), nil
>> }
>> }
>>
>> // use it:
>>
>> var mrs MyReader string
>> var mrb MyReader []byte
>>
>> s := "Golang"
>> bs := make([]byte, 100)
>>
>> var rs Reader string = mrs
>> _, _ = rs.Read(s)
>> var rb Reader []byte = mrb
>> _, _ = rb.Read(bs)
>>
>> rb = (MyReader string)(rs)
>> _, _ = rb.Read(bs)
>> rs = (MyReader []byte)(rb)
>> _, _ = rs.Read(s)
>>
>>
>>
>> On Wednesday, August 26, 2020 at 1:16:49 PM UTC-4 Di gg wrote:
>>
>>>
>>>
>>> https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md
>>>
>>> This is an alternative generic idea set, which should be Go 1 compatible.
>>> It tries to use the same syntax forms as builtin generics.
>>>
>>> Different from the official draft, it adopts a from-top-to-bottom 
>>> pattern,
>>> instead of the from-bottom-to-top pattern, to describe type parameters.
>>> For example, given a map type parameter M, its key and element types 
>>> could
>>> be denoted as M.key and M.element, whereas to use a map type parameter,
>>> its key and elements must also present in the declaration signarure or 
>>> constraint definitions.
>>>
>>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d465715d-c381-486e-8a1f-617a68f82b59n%40googlegroups.com.


[go-nuts] Re: some interesting ideas: reuse package keyword to declare generics

2020-09-11 Thread Di gg
Sorry, the last 4 lines should be:

rs = (MyReader string)(rb)
_, _ = rs.Read(s)
rb = (MyReader []byte)(rs)
_, _ = rb.Read(bs)

On Friday, September 11, 2020 at 11:00:12 PM UTC-4 Di gg wrote:

> An example demostrating how to let Reader.Read support both string and 
> []byte parameters.
>
> package readonlybytes[T] (
> assert T.kind & (String | Slice)
> )
>
> package Reader[T] (
> assert readonlybytes[T]
> ){
> type Reader interface {
> Read(bytes T)(n int, err error)
> }
> }
>
> package MyReader[T](
> assert T.kind & (String | Slice)
> ){
> type MyReader struct{}
>
> type (r *MyReader) Read(s T)(int, error) {
> return len(s), nil
> }
> }
>
> // use it:
>
> var mrs MyReader string
> var mrb MyReader []byte
>
> s := "Golang"
> bs := make([]byte, 100)
>
> var rs Reader string = mrs
> _, _ = rs.Read(s)
> var rb Reader []byte = mrb
> _, _ = rb.Read(bs)
>
> rb = (MyReader string)(rs)
> _, _ = rb.Read(bs)
> rs = (MyReader []byte)(rb)
> _, _ = rs.Read(s)
>
>
>
> On Wednesday, August 26, 2020 at 1:16:49 PM UTC-4 Di gg wrote:
>
>>
>>
>> https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md
>>
>> This is an alternative generic idea set, which should be Go 1 compatible.
>> It tries to use the same syntax forms as builtin generics.
>>
>> Different from the official draft, it adopts a from-top-to-bottom pattern,
>> instead of the from-bottom-to-top pattern, to describe type parameters.
>> For example, given a map type parameter M, its key and element types could
>> be denoted as M.key and M.element, whereas to use a map type parameter,
>> its key and elements must also present in the declaration signarure or 
>> constraint definitions.
>>
>>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/89a51517-3b2b-46a9-ae72-70a01172bfccn%40googlegroups.com.


[go-nuts] Re: some interesting ideas: reuse package keyword to declare generics

2020-09-11 Thread Di gg
An example demostrating how to let Reader.Read support both string and 
[]byte parameters.

package readonlybytes[T] (
assert T.kind & (String | Slice)
)

package Reader[T] (
assert readonlybytes[T]
){
type Reader interface {
Read(bytes T)(n int, err error)
}
}

package MyReader[T](
assert T.kind & (String | Slice)
){
type MyReader struct{}

type (r *MyReader) Read(s T)(int, error) {
return len(s), nil
}
}

// use it:

var mrs MyReader string
var mrb MyReader []byte

s := "Golang"
bs := make([]byte, 100)

var rs Reader string = mrs
_, _ = rs.Read(s)
var rb Reader []byte = mrb
_, _ = rb.Read(bs)

rb = (MyReader string)(rs)
_, _ = rb.Read(bs)
rs = (MyReader []byte)(rb)
_, _ = rs.Read(s)



On Wednesday, August 26, 2020 at 1:16:49 PM UTC-4 Di gg wrote:

>
>
> https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md
>
> This is an alternative generic idea set, which should be Go 1 compatible.
> It tries to use the same syntax forms as builtin generics.
>
> Different from the official draft, it adopts a from-top-to-bottom pattern,
> instead of the from-bottom-to-top pattern, to describe type parameters.
> For example, given a map type parameter M, its key and element types could
> be denoted as M.key and M.element, whereas to use a map type parameter,
> its key and elements must also present in the declaration signarure or 
> constraint definitions.
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cd343e62-925f-4185-af3d-8c04c16aefbfn%40googlegroups.com.


[go-nuts] Re: some interesting ideas: reuse package keyword to declare generics

2020-08-26 Thread Di gg
> whereas to use a map type parameter,
its key and elements must also present in the declaration signarure or 
constraint definitions.

sorry, missed some words here. It should be

whereas for the official draft, ...

On Wednesday, August 26, 2020 at 1:16:49 PM UTC-4 Di gg wrote:

>
>
> https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md
>
> This is an alternative generic idea set, which should be Go 1 compatible.
> It tries to use the same syntax forms as builtin generics.
>
> Different from the official draft, it adopts a from-top-to-bottom pattern,
> instead of the from-bottom-to-top pattern, to describe type parameters.
> For example, given a map type parameter M, its key and element types could
> be denoted as M.key and M.element, whereas to use a map type parameter,
> its key and elements must also present in the declaration signarure or 
> constraint definitions.
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/816c221d-f65c-4c26-81d4-126d6080c5b4n%40googlegroups.com.


[go-nuts] some interesting ideas: reuse package keyword to declare generics

2020-08-26 Thread Di gg

https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md

This is an alternative generic idea set, which should be Go 1 compatible.
It tries to use the same syntax forms as builtin generics.

Different from the official draft, it adopts a from-top-to-bottom pattern,
instead of the from-bottom-to-top pattern, to describe type parameters.
For example, given a map type parameter M, its key and element types could
be denoted as M.key and M.element, whereas to use a map type parameter,
its key and elements must also present in the declaration signarure or 
constraint definitions.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/facd3bf8-1f62-4b6e-b518-28f33738cb3an%40googlegroups.com.