4 ms·
You'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:
by uryga 8y ago
You'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.