Live data from Hacker News

Show HN: Fo: An experimental language which adds generics on top of Go

github.com

101–110 of 125 posts

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#101
post #75

Earlier quoted context omitted.

Try implementing a shared map type where access is protected by a mutex and otherwise works just like Go's builtin map type (which is a generic map type).

Why would I need to re-implement what is already there?

It's honestly hard for me to tell whether you're trolling or not, but all you need to do is compare and contrast the API of the built in map type and sync.Map. One has compile time type safety and the other one doesn't.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#102
post #44

Author here. I've been working on Fo part time for 4 months. Feel free to ask me anything.

Did you consider parameterized packages? The idea is you can declare a set of related objects/types/methods as well as have concrete type specific initialization. E.g. package stack[t] type Type []t func New() Type { return Type{} } ... Then it can be used so: import s “stack”[int] var s1 = s.New()

I’ve seen this in ocaml and always thought it strange. I think it’s useful, but binding it to a package seems odd since packages are units of code distribution or some such.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#103

Earlier quoted context omitted.

Interesting, you have a point actually. I would have thought that the performance cost of calling through an interface would be negligible, but I'm wrong about that: https://github.com/golang/go/issues/20116 The issues linked at the end there are interesting reads, and maybe they'll do something about this by Go 1.11. Having said all that, will an implementation of your code with generics be all that much faster? Or…

> Having said all that, will an implementation of your code with generics be all that much faster? Likely yes. If generics are implemented via monomorphization, then you can avoid the overhead of virtual calls necessitated by interfaces. It is possible that the compiler could become smart enough to devirtualize calls through interfaces.

Pretty sure devirtualization is a whole program optimization in the general case, and I don’t see the Go dev team Pershing that in the next couple of years.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#104
post #44

Earlier quoted context omitted.

Did you consider parameterized packages? The idea is you can declare a set of related objects/types/methods as well as have concrete type specific initialization. E.g. package stack[t] type Type []t func New() Type { return Type{} } ... Then it can be used so: import s “stack”[int] var s1 = s.New()

I’ve seen this in ocaml and always thought it strange. I think it’s useful, but binding it to a package seems odd since packages are units of code distribution or some such.

It is not strange if you think of objects in OOP as modules/packages you can inherit from.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#105

Earlier quoted context omitted.

Image allows you to do this more or less. The problem to be solved here is that if you write the resize logic just once, you are accessing pixels from the image via the interface in a tight loop, and most of the time taken by your image resizer is the overhead of that access.

Interesting, you have a point actually. I would have thought that the performance cost of calling through an interface would be negligible, but I'm wrong about that: https://github.com/golang/go/issues/20116 The issues linked at the end there are interesting reads, and maybe they'll do something about this by Go 1.11. Having said all that, will an implementation of your code with generics be all that much faster? Or…

Go 1.11 is already feature freeze and it doesn't seem likely.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#106
post #98

Earlier quoted context omitted.

And I've read about many people using Go and wishing for generics from day one.

It's mostly a "day 1" concern, is all. Once you get over it you find that you can do whatever you need.

All turing complete languages can be used to do whatever we need, doesn't mean all of them are usefull to keep using in 2018.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#108
post #44

Earlier quoted context omitted.

Did you consider parameterized packages? The idea is you can declare a set of related objects/types/methods as well as have concrete type specific initialization. E.g. package stack[t] type Type []t func New() Type { return Type{} } ... Then it can be used so: import s “stack”[int] var s1 = s.New()

I’ve seen this in ocaml and always thought it strange. I think it’s useful, but binding it to a package seems odd since packages are units of code distribution or some such.

Think of it as a package macro.

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#109
post #44

Author here. I've been working on Fo part time for 4 months. Feel free to ask me anything.

Did you consider parameterized packages? The idea is you can declare a set of related objects/types/methods as well as have concrete type specific initialization. E.g. package stack[t] type Type []t func New() Type { return Type{} } ... Then it can be used so: import s “stack”[int] var s1 = s.New()

I think parameterized packages are a great idea. It would be a light-weight way of getting just a bit of generic code into go.

I made gotemplate to explore that idea

https://github.com/ncw/gotemplate

This requires a round of `go generate` for the actual code generation, but otherwise quite a similar experience.

Having it built in would be great!

Re: Show HN: Fo: An experimental language which adds generics on top of Go

#110

Earlier quoted context omitted.

> Having said all that, will an implementation of your code with generics be all that much faster? Likely yes. If generics are implemented via monomorphization, then you can avoid the overhead of virtual calls necessitated by interfaces. It is possible that the compiler could become smart enough to devirtualize calls through interfaces.

Pretty sure devirtualization is a whole program optimization in the general case, and I don’t see the Go dev team Pershing that in the next couple of years.

> I don’t see the Go dev team Pershing that in the next couple of years

Agreed. But if I didn't mention it, I'm sure someone would have felt obligated to respond with a "well actually..."

Post reply on HN