Term for Function Inverse to Constructor – Functional Programming

datafunctional programminghaskellterminology

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 newtypes) 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?

The questions are:

  • How do we call unwrap in functional programming? Deconstructor? Destructor? Or by some other term?
  • And to clarify, is this/other terminology applicable to other functional languages, or is it used just in the Haskell?
  • Perhaps also, is there any terminology for this in general, in non-functional languages?

I've seen both terms, 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), or

newtype DList a = DL { unDL :: [a] -> [a] }

The unDL function is our deconstructor, which removes the DL constructor. …

in The Real World Haskell.

Best Answer

There are several terms for the concept. Deconstructing is what I believe is common in Haskell circles, it is what Real World Haskell calls it. I believe the term destructuring(or destructuring bind) is common in Lisp circles.

Related Topic