On Thu, Sep 6, 2018 at 10:29 AM, jimmy frasche <soapboxcic...@gmail.com> wrote:
>
> Contracts are a brilliant solution to the problem on an intellectual
> level. I really am impressed by how deftly they tackle the stated
> problem. But I am concerned about their usability on the practical
> level. The idea is simple but its user interface is not. I don't buy
> the claim that it's okay because a priest-class will be the only ones
> writing generic code. Everyone will still have to read it and deal
> with it.

This is clearly a key issue.  I happen to think that contracts are
fairly clear for the reader: take your type argument and see if the
contract body works.  I feel that everyone who knows Go will be able
to do that.  But maybe that's just me.


> Scaling back the problem to simply not include operators and fields at
> all looks like it eliminates so much of the complexity in the
> implementation and its user interface. Any such limited solution
> increases the boilerplate of using generics when operators and fields
> come in to play, certainly, but I think the majority of use-cases for
> generics are going to be data structures and algorithms more generally
> expressible without operators anyway (few types have a < operator but
> any type can have a Less method and without type classes in the
> haskell/etc. there still isn't a way to handle both without accepting
> a Less method and requiring a wrapper for types that have a <
> operator).
>
> Is it really *necessary* for generics to support operators and fields?

It's not necessary to support fields but I think it really is
necessary to support operators.  I claim that, other than type safe
data structures, the number one generic function that people want to
write is Min (or Max).  I don't think we can plausible add a generics
system to Go that doesn't permit writing a Min function.

contract comparable(x T) {
    x < x
}

func Min(type T comparable)(a, b T) T {
    if a < b {
        return a
    }
    return b
}

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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to