What's the proper term for a function inverse to a constructor - to unwrap a value from a data type?

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 21:48 UTC
Read the original article Hit count: 255

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.

© Programmers or respective owner

Related posts about terminology

Related posts about functional-programming