Take the 2-minute tour ×

Looking into Haskell's standard library we can see:


newtype WrappedMonad m a = WrapMonad { unwrapMonad :: m a }

newtype Sum a = Sum { getSum :: a }

Apparently, there (at least) 3 different prefixes used to unwrap a value inside a newtype: un-, run- and get-. (Moreover run- and get- capitalizes the next letter while un- doesn't.) This seems confusing.

  • Are there any reasons for that, or is that just a historical thing?
  • If I design my own newtype, what prefix should I use and why?
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

The convention regarding capitalization is that the first letter of each word is capitalized. So the "w" in "unwrap" is lower-case because "unwrap" is one word, i.e. it's "unwrap [the] monad", not "un wrap [the] monad".

The reason that runStateT is named runStateT is that this best describes how the function is used - it's used to execute/run a state transformer. It wouldn't make sense to call the other deconstructors in your example runSomething because they're not used to run or execute anything.

The distinction between get and unwrap seems a bit more arbitrary (at least for records with only one member), but in this case I think the word unwrap was simply chosen because it fits nicely with the name WrappedMonad.

In the end I'd say that it's not necessary to pick a name that unmistakably marks a function as being a destructor because that's not really relevant. So the "convention" for naming deconstructors is simply to pick one that best describes what it does and how it's supposed to be used.

share|improve this answer
add comment

Your Answer


