3 ms·
In languages with destructuring syntax, you get the best of both worlds.
by AlexCoventry 8y ago
In languages with destructuring syntax, you get the best of both worlds.
- jstimpfle 8y agoHow so? It's just a syntax. It doesn't remove the physical coupling of elements that are infrequently used as a unit.
- uryga 8y agoYou're right, but it can still make it obvious to the reader that you don't actually use all of the struct in a function. I think GP meant something like this: (Haskell syntax) -- struct with three fields data Bar = Bar { x :: Int , y :: Int , z :: String } -- function from Bar to Baz foo :: Bar -> Baz foo (Bar _ _ z) = ... `foo` takes a whole `Bar`, but in the pattern matching bit you explicitly say you don't need x and y by using `_`. Also, by enabling an extension[0], you can instead do: foo :: Bar -> Baz foo (Bar {z}) = ... Which I guess gets pretty close to what I want. [0] NamedFieldPuns
- AlexCoventry 8y agoYeah, that's what I meant, especially the second example, which is closer to my experience from clojure.