Hacker News new | ask | show | jobs
by keymone 3280 days ago
last time i tried using funcs a lot it turned out that it's not possible to typedef a function signature and use it to pass funcs as arguments which is very unfortunate. is this by design or is it getting fixed?
1 comments

notice that you had to repeat function signature on line 14

    print("hello", func(msg string) { ... })
when signature is much larger it becomes very annoying. something like

    print("hello", Printer(msg) { ... })
would be perfect, but something something golang generics something?
Not sure what this has to do with generics, Go requires types for function arguments. If your anonymous function gets clumsy and too big in place, just use a named function not an anonymous one:

    print("hello", myprinter)
https://play.golang.org/p/3sNOeVIhqi
point is typedefs aren't reusable at anonymous function declarations. imo that sucks. that's all i wanted to say.
You could always declare the method on the Printer type...

https://play.golang.org/p/4MG8kgGEGM

where's the anonymous function with reuse of typedef in there?
No, it's just a syntax issue, not a generics issue.

Are there any manifestly-typed languages that work that way, though? I'm having trouble thinking of one, though given the number out there I won't be surprised if there is.

maybe there are none, but wouldn't that be really nice?