2 ms·
It depends on what you mean with generics. If it's only parametric polymorphism and ad hoc polymorphism then I would Haskell solves it trivially and very easy t
by rowanG077 2y ago
It depends on what you mean with generics. If it's only parametric polymorphism and ad hoc polymorphism then I would Haskell solves it trivially and very easy to understand. If you mean it to include full "template" metaprogramming or type level programming then I'm not sure.
- grandempire 2y agoIf go copies this design from Haskell would it look simple?
- rowanG077 2y agoSure. Type classes are extremely simple. Go generics are already superficially similar to type classes.
- grandempire 2y agoSuppose I have a generic array-like collection containing a type a and I want to write a map function to take it to a collection of type b. In Haskell this is something like map :: (a->b) -> C a -> C b Can you share what that would like in Go with type classes?
- rowanG077 2y agoIt's possible to define an map function for a container today https://go.dev/play/p/zcP6FZcBzyC https://go.dev/play/p/zcP6FZcBzyC You can also define an fmap interface that doesn't actually map the type, but can apply function that do not change the type: https://go.dev/play/p/836wr3nuw4U https://go.dev/play/p/836wr3nuw4U But currently I don't think it's possible to combine this. That is have an fmap as it is in Haskell. You would need to capability to add generic arguments to an interface. It could look something like this: https://go.dev/play/p/E_emmGUOoIz https://go.dev/play/p/E_emmGUOoIz
- grandempire 2y agoThis is very helpful. Thanks.