[Haskell-cafe] APIs

Henning Thielemann lemming at henning-thielemann.de
Tue May 24 13:42:39 EDT 2005


On Thu, 19 May 2005 ajb at spamcop.net wrote:

> G'day all.
> 
> Quoting Jérémy Bobbio <jeremy.bobbio at etu.upmc.fr>:
> 
> > One of the best bad example is the use of boolean as arguments.
> 
> Oh, yes.  That's a pet peeve of mine.  About 99% of boolean arguments
> should be meaningful two-valued enumerated types.  It's literally a
> one-liner to create such an enumerated type, so there's no excuse.

The documentation effect and type safety provided by two-valued enumerated 
types is indeed much greater. But one needs a conversion from Bool to the 
enumeration if one wants to pass the result of a logic operation to the 
function. What about records with named fields, especially if more options 
are needed?

data CreateDirectoryOptions = Cons {createParents :: Bool}

createDirectory (Cons {createParents = True}) "dir"


More information about the Haskell-Cafe mailing list