What's the proper term for a function inverse to a constructor? Deconstructor, destructor, or something else?
Posted
by
Petr Pudlák
on Programmers
See other posts from Programmers
or by Petr Pudlák
Published on 2012-10-12T12:18:14Z
Indexed on
2012/10/12
15:48 UTC
Read the original article
Hit count: 283
Edit: I'm rephrasing the question a bit. Apparently I caused some confusion because I didn't realize that the term destructor is used in OOP for something quite different - it's a function invoked when an object is being destroyed. In functional programming we (try to) avoid mutable state so there is no such equivalent to it. (I added the proper tag to the question.)
Instead, I've seen that the record field for unwrapping a value (especially for single-valued data types such as newtype
s) is sometimes called destructor or perhaps deconstructor. For example, let's have (in Haskell):
newtype Wrap = Wrap { unwrap :: Int }
Here Wrap
is the constructor and unwrap
is what?
I've seen both, for example:
... Most often, one supplies smart constructors and destructors for these to ease working with them. ...
at Haskell wiki, or
... The general theme here is to fuse constructor - deconstructor pairs like ...
at Haskell wikibook (here it's probably meant in a bit more general sense).
The questions are:
- How do we call
unwrap
in functional programming? Deconstructor? Destructor? Or by some other term? - And to clarify, is this terminology applicable to other functional languages, or is it used just in the Has
© Programmers or respective owner