On Fri, Sep 7, 2018 at 9:29 AM 'Axel Wagner' via golang-nuts <golang-nuts@googlegroups.com> wrote: > On Fri, Sep 7, 2018 at 12:37 AM Ian Lance Taylor <i...@golang.org> wrote: >> Interesting point. But is there any way to solve it short of >> explicitly listing types? Is there any generics system in any >> language that avoids this problem? > > I'm not saying this would be the solution, but since you asked: Refinement > types (implemented e.g. in Liquid Haskell).
Drifting off-topic, but while refinement types sound similar, they're not really applicable (and refinement types are obviously type related but not generics related), right? IIUC, refinement lets you narrow the set of acceptable *values*, starting from a given *type*. For example, given an "integer" type, derive a new type "positive integer", or given a "binary tree" type, derive a new type "balanced binary tree". Refinements are predicates on *values*: whether or not a value is in the smaller subset. But what we'd want here is predicates on *types*, such as "we accept all numeric types T that can represent -1". It's not immediately obvious how to express a type-predicate using value-predicates (refinements). It's also not obvious, starting from any given type, how to 'narrow' it (conditional on *value*) to enforce "the *type* can represent -1", or if that's even the right way to think about it. -- 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.