Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-20 Thread Ian Lance Taylor
On Mon, Dec 20, 2021 at 4:04 AM Leonard Mittmann wrote: >> >> As to _why_ this is the case, the generics proposal has a section about that: >> https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#permitting-constraints-as-ordinary-interface-types > > @Jason

Re: [go-nuts] Create non-variadic functions without existingType using reflection

2021-12-20 Thread Ian Lance Taylor
On Mon, Dec 20, 2021 at 1:05 PM 'Ankit Gupta' via golang-nuts wrote: > > If I have argument type for a function: is it possible to create a function > with those? > Note: > - we don't have reflect type for the function to be created so makeFunc can > not be simply used. > - function inputTypes

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread Robert Engels
This is a task for a parser - and the parser can be type safe -but the constraints for something as complex as html aren’t typically expressed in types but rather bnf or similar. You can look at the Java html renderer/parser and it uses type safe nodes but it still has a resilient parser

[go-nuts] Create non-variadic functions without existingType using reflection

2021-12-20 Thread 'Ankit Gupta' via golang-nuts
Hey Folks, If I have argument type for a function: is it possible to create a function with those? *Note:* - we don't have reflect type for the function to be created so makeFunc can not be simply used. - function inputTypes can differ so variadic can not be leveraged here. - number of

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread Michael Ellis
Thanks, Axel & Robert. As I said in the first post, the package already works well for my purposes (and apparently for the few others who use it). It allows defining web content more concisely than raw HTML and makes the full power of Go available for composing repetitive page structures. I

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread 'Axel Wagner' via golang-nuts
Oh, forgot the footnote: [1] Note that even that doesn't *actually* work, as `*HtmlNode` would become a parametric type, so it would have to be instantiated to be used in the constraint - you'd have to write `type HtmlNode[T string | *HtmlNode[Something]]`. And the fact that there is no actual

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread 'Axel Wagner' via golang-nuts
On Mon, Dec 20, 2021 at 7:07 PM Michael Ellis wrote: > >Just to be clear, the way I understood you is that you want HtmlTree.C to > be a slice which has elements which can each either be a string or an > *HtmlTree - i.e. you want these to be mixed in a single slice. Correct? > > Actually, no.

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread Robert Engels
You create structs like StringNode and HtmlNode that implement the common needed operations. Imagine a Render() method for a string you convert to html, for an html node you render recursively. Or similar. If an HtmlNode is not a leaf node it needs recursive operations. > On Dec 20, 2021,

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread Michael Ellis
On Monday, December 20, 2021 at 1:33:49 PM UTC-5 ren...@ix.netcom.com wrote: > You should use interfaces and a “node” type. > Hmm, I tried type Node interface { string | []*HtmlTree } type HtmlTree struct { T string // html tagname, e.g. 'head' A string //

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread Robert Engels
You should use interfaces and a “node” type. > On Dec 20, 2021, at 12:07 PM, Michael Ellis wrote: > > >Just to be clear, the way I understood you is that you want HtmlTree.C to > be a slice which has elements which can each either be a string or an > *HtmlTree - i.e. you want these to be

[go-nuts] Re: Gradual change of package path

2021-12-20 Thread Sean Liao
You're right about the source of the error you're seeing (subfolder of root + independent module). If you just want to get rid of the error, update your versions of the 2 modules so they both have the same view of module boundaries. But you don't need 2 separate modules for this, and you

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread Michael Ellis
>Just to be clear, the way I understood you is that you want HtmlTree.C to be a slice which has elements which can each either be a string or an *HtmlTree - i.e. you want these to be mixed in a single slice. Correct? Actually, no. An HtmlTree instance whose content is a string is a terminal

[go-nuts] Gradual change of package path

2021-12-20 Thread Levieux Michel
Hi all, I have a use-case which I'm not sure I'll be able to tackle using current tooling but just to be sure, I'm asking here. I have a package which originally looked like: / /go.mod /package_name /other_packages... there are no go files at the root of the module, and the code that is "meant"

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread 'Axel Wagner' via golang-nuts
Just to be clear, the way I understood you is that you want HtmlTree.C to be a slice which has elements which can each either be a string or an *HtmlTree - i.e. you wan these to be mixed in a single slice. Correct? Because that is not a use case for generics, it's a use case for sum types (which

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread Michael Ellis
> They can't, sorry. Ok. Thanks, Axel. Saves me wasting more time. In the past 3 years of using Go, this is the only use case where I've really wanted generics (other cases I've encountered so far are easily handled with code generation). -- You received this message because you are

Re: [go-nuts] Generic member of recursive struct

2021-12-20 Thread 'Axel Wagner' via golang-nuts
On Mon, Dec 20, 2021 at 3:20 PM Michael Ellis wrote: > I've got a package, github.com/Michael-F-Ellis/goht, that supports > creating HTML docs in Go. It works well, for my purposes at least, but > I've always been bothered by having to use []interface{} to define the > struct member, C, that

[go-nuts] Generic member of recursive struct

2021-12-20 Thread Michael Ellis
I've got a package, github.com/Michael-F-Ellis/goht, that supports creating HTML docs in Go. It works well, for my purposes at least, but I've always been bothered by having to use []interface{} to define the struct member, C, that supports recursion. type HtmlTree struct { T

Re: [go-nuts] Go 1.18. Type Constraints are (not) interfaces!?

2021-12-20 Thread Leonard Mittmann
> > As to _why_ this is the case, the generics proposal has a section about > that: > > https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md#permitting-constraints-as-ordinary-interface-types @Jason Phillips Thanks for pointing me here. @Ian Lance Taylor I

[go-nuts] Self promotion - New Book, "Practical Go: Building Scalable Network and Non-Network Applications"

2021-12-20 Thread Amit Saha
Hi all, I wanted to share that my latest book is on Go programming and it is now out electronically as well as in print. It is titled "Practical Go: Building Scalable Network and Non-Network Applications" (https://practicalgobook.net/) and published by Wiley publications. The book targets readers