Quick question about the new Contracts Draft Proposal

268 views
Skip to first unread message

Jon Bodner

unread,
Jul 28, 2019, 4:15:41 PM7/28/19
to golang-nuts
Hello,

I did a first read through the proposal and it looks very good. I had one question: when giving the example of how to implement Sorting using orderedSlice, the type parameter is declared to be comparable. Should that be contracts.Ordered?

Thanks,

Jon

Mandolyte

unread,
Jul 28, 2019, 7:55:50 PM7/28/19
to golang-nuts
I missed this. Do you have a link to the proposal?

Jon Bodner

unread,
Jul 28, 2019, 8:11:40 PM7/28/19
to golang-nuts

alanfo

unread,
Jul 29, 2019, 7:55:09 AM7/29/19
to golang-nuts
 Yes, it should be contracts.Ordered to justify the use of the '<' operator.

The proposed new built-in comparable contract will only permit one to use '==' or '!='.

I agree that the revised design is very good, contracts are now far more intelligible than they were and the whole thing just feels much more Go-like to me :)

As the response so far has been generally positive, hopefully it won't be too long before this proceeds to the 'proposal' stage.

Alan

Ian Lance Taylor

unread,
Jul 29, 2019, 2:17:22 PM7/29/19
to Jon Bodner, golang-nuts
On Sun, Jul 28, 2019 at 1:15 PM Jon Bodner <j...@bodnerfamily.com> wrote:
>
> I did a first read through the proposal and it looks very good. I had one question: when giving the example of how to implement Sorting using orderedSlice, the type parameter is declared to be comparable. Should that be contracts.Ordered?

Yes, thanks. Will update.

Ian

Mandolyte

unread,
Jul 29, 2019, 5:35:34 PM7/29/19
to golang-nuts
In this code snippet:
func Map(type S, Element)(s S, f func(Element) Element) S {
	r := make(S, len(s))
	for i, v := range s {
		r[i] = f(s)
	}
	return r
}
Shouldn't the line in the loop be: r[i] = f(v)

Ian Lance Taylor

unread,
Jul 29, 2019, 8:04:26 PM7/29/19
to Mandolyte, golang-nuts
On Mon, Jul 29, 2019 at 2:35 PM Mandolyte <ceci...@gmail.com> wrote:
>
> In this code snippet:
>>
>> func Map(type S, Element)(s S, f func(Element) Element) S {
>> r := make(S, len(s))
>> for i, v := range s {
>> r[i] = f(s)
>> }
>> return r
>> }
>
> Shouldn't the line in the loop be: r[i] = f(v)

Yes. Thanks.

Ian

> On Monday, July 29, 2019 at 2:17:22 PM UTC-4, Ian Lance Taylor wrote:
>>
>> On Sun, Jul 28, 2019 at 1:15 PM Jon Bodner <j...@bodnerfamily.com> wrote:
>> >
>> > I did a first read through the proposal and it looks very good. I had one question: when giving the example of how to implement Sorting using orderedSlice, the type parameter is declared to be comparable. Should that be contracts.Ordered?
>>
>> Yes, thanks. Will update.
>>
>> Ian
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/87f10070-394b-4500-a8d3-567562e12d5d%40googlegroups.com.

Qais Patankar

unread,
Jul 30, 2019, 8:45:43 AM7/30/19
to golang-nuts
In this:

func Map(type S, Element)(s S, f func(Element) Element) S {

Why is Slice not mentioned anywhere?


Shouldn't it be:

func Map(type S, Element Slice) [..]


On Tuesday, 30 July 2019 09:04:26 UTC+9, Ian Lance Taylor wrote:
On Mon, Jul 29, 2019 at 2:35 PM Mandolyte <ceci...@gmail.com> wrote:
>
> In this code snippet:
>>
>> func Map(type S, Element)(s S, f func(Element) Element) S {
>> r := make(S, len(s))
>> for i, v := range s {
>> r[i] = f(s)
>> }
>> return r
>> }
>
> Shouldn't the line in the loop be: r[i] = f(v)

Yes.  Thanks.

Ian

> On Monday, July 29, 2019 at 2:17:22 PM UTC-4, Ian Lance Taylor wrote:
>>
>> On Sun, Jul 28, 2019 at 1:15 PM Jon Bodner <j...@bodnerfamily.com> wrote:
>> >
>> > I did a first read through the proposal and it looks very good. I had one question: when giving the example of how to implement Sorting using orderedSlice, the type parameter is declared to be comparable. Should that be contracts.Ordered?
>>
>> Yes, thanks.  Will update.
>>
>> Ian
>
> --
> 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 golan...@googlegroups.com.

alan...@gmail.com

unread,
Jul 30, 2019, 10:10:50 AM7/30/19
to golang-nuts
Yes, it should.

Alan
Reply all
Reply to author
Forward
0 new messages