Nice work. But, serious question - When going with parameterized types I know from Haskell how you always end up needing one more language extension and always end up banging your head against the wall that separates types and values a little more. At least if you're not a math genius, but probably even then. And from Java I know that there's a pretty trivial example that showcases how its Generics implementation is…
Haskell is a proving ground, so it's picked up a number of ideas that never quite panned out. I think you can identify a core set of features that are pretty reasonable. I think that'd be type classes, constraints, and functional dependencies. If they made a handful of extensions standard (GADTs, etc.) it would mostly Do What You Want without a lot of prodding. > And from Java I know that there's a pretty trivial exa…
Show HN: Fo: An experimental language which adds generics on top of Go
111–120 of 125 posts
Re: Show HN: Fo: An experimental language which adds generics on top of Go
#112Earlier quoted context omitted.
Isn't interface{} a generic?
No, interface {} is more like void pointers in C and C++ or Object in C# and Java. It can hold values of any type. One of the major selling points of actual generics is that they provide type safety, but interface {} doesn't provide that.
Re: Show HN: Fo: An experimental language which adds generics on top of Go
#113Earlier quoted context omitted.
Well, it's not quite fair to say it's "plain Go." The compiler converts expressions like x, ok := m["foo"] into function calls. User-level code can't define syntax sugar like that. Also, the hashmap implementation imports some internal packages, so you can't just copy and paste it. (I would know, because I mostly did copy and paste it for one of my own projects: https://github.com/lukechampine/randmap )
When discussing whether go has generics, "plain go" is a reasonable thing to say. Besides it's a compiler. It's going to take an input in format X and translate it to an output in format Y. That's just what they do. Syntactic sugar debates aside there's still no generics in there.
My point is, Go type system DOES support generics, but only for "primitive" types, not for user-defined types.
Re: Show HN: Fo: An experimental language which adds generics on top of Go
#114Author here. I've been working on Fo part time for 4 months. Feel free to ask me anything.
Hi there! I worked on something similar a while ago: a compile-to-Go superset that adds some generic functions/methods. You may have come across it: https://github.com/lukechampine/ply My perspective was that when I find myself wishing for generics in Go, what I really want is not full-blown generic types and functions, but rather a few helper functions like map/filter/reduce, or converting a map to a slice, etc. Hav…
Local types are an edge case I'll need to spend more time working on. The type-checker won't have any problems; the real question is how to generate the appropriate Go code. One solution might be to move the local type into a higher scope during code-generation. Another might be inlining the relevant generic types in the same scope as the local type. Finally, the best solution might just be to say this sort of thing isn't allowed and the compiler will return an error.
Imports aren't supported right now, but it's one of the most important things I need to work on next. It'll be pretty tricky, but I'm confident I can find a solution.
The fortunate thing about the approach I'm using with Fo is that I have complete control over the parser, type-checker, and code-generator. At the cost of having significantly more complexity, I have the flexibility to tackle these sorts of edge cases without relying solely on existing tooling.
Re: Show HN: Fo: An experimental language which adds generics on top of Go
#115Author 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()
Re: Show HN: Fo: An experimental language which adds generics on top of Go
#116Author here. I've been working on Fo part time for 4 months. Feel free to ask me anything.
What does the implementation look like under the hood? What are the limitations of your approach (i.e. generic interfaces) and are they fundamental or just on the todo list?
Generic interfaces are pretty fundamental IMO. It's something I plan to add to the language before the v1 release.
Re: Show HN: Fo: An experimental language which adds generics on top of Go
#117Author here. I've been working on Fo part time for 4 months. Feel free to ask me anything.
Any plans to add formal sum types (as opposed to interface hacks)?
Re: Show HN: Fo: An experimental language which adds generics on top of Go
#118Re: Show HN: Fo: An experimental language which adds generics on top of Go
#119Author here. I've been working on Fo part time for 4 months. Feel free to ask me anything.
Can you do ad-hoc or bounded polymorphism? What about recursive types?
Re: Show HN: Fo: An experimental language which adds generics on top of Go
#120Is there any support for bounded type variables? Or plans to add them?