-
Notifications
You must be signed in to change notification settings - Fork 35
support for immutable values #5
Comments
Could you give some concrete example for this? |
This project doesn't seem to be focused on data structures... You could try https://github.com/tobgu/peds to get immutability a la carte |
@TrueFurby I think @campoy is talking about a something like type MyType struct {
X int
Y string
}
let m = MyType{X: 1, Y: "Immutable"}
// You can't then, modify the internals of a composite structure.
m.X = 2
m.Y = "Can't mutate me"
// You also can't change the binding to something else.
m = MyType{X: 2, Y: "Can't rebind variable m either"} Please correct me if I'm wrong, but that's what I understood from "some form of immutability". |
I think @campoy may be referring to persistent data structures? |
Oh, I see. Thanks for pointing it out! That would be a huge change right (even compared to adding generics)? Go isn't even partially persistent. |
I recognize that immutability is a core part of functional programming. However, I'm not sure how we could enforce this at the compiler level, especially given the existence of the I think immutability may be something best left to libraries to implement. For example, if you are writing a |
Yeah, but I would expect at least slices to be immutable? |
@campoy I'm not sure what you are proposing exactly. Can you elaborate? How would this work with the existing slice type in Go? |
I'm not sure how it would be implemented. This is more of a question / proposal rather than a "you need to fix this" issue. |
Hey there,
So I'm actually quite interested on this project, but the first thing I expected to find in a functional version of Go was some form of immutability.
Have you considered adding such a feature? I'd be curious on how it would match the rest of the language!
The text was updated successfully, but these errors were encountered: