2 ms·
Suppose 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
by grandempire 2y ago
Suppose 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.