[Haskell-cafe] Investigating single-letter type variables

Phil Ruffwind rf at rufflewind.com
Fri Aug 11 02:10:29 UTC 2017


> (2) If I'm looking at a new library for the first time and trying to figure
> out what a type variable stands for, is there a canonical way to do it?

Type variables inherently don't have any meaning – the meaning only
comes from how they are used and how they are constrained.

Therefore, you need to look for clues based on (1) the constraints on
the type variable, if any, and (2) the types that use the variable.

For parsec it's pretty easy because the type variables are often
constrained by Stream and used by the ParsecT type.  The documentation
of parsec is really detailed: both Stream and ParsecT tell you precisely
what 's' and 'm' are, and the library is very consistent with this
convention.  IMO, good documentation should always explain every type
variable in every `data` or `newtype` declaration.

I would say part of the reason Haskell uses single-letter variables a
lot is that a lot of the code are very general and the authors did not
want to impose their domain-specific interpretation on it.  In some
situations (e.g. application code, domain-specific libraries), writing
out the variables in full can be meaningful, but in library code this is
rare.


More information about the Haskell-Cafe mailing list