[Haskell-cafe] APIs

Benjamin Franksen benjamin.franksen at bessy.de
Tue May 24 18:46:20 EDT 2005


On Wednesday 25 May 2005 00:11, Jan-Willem Maessen wrote:
> On May 24, 2005, at 5:28 PM, John Meacham wrote:
> > [various ways of capturing options passed to functions
> > discussed...]
> >
> > I think it is easier just to declare it as Enum..
> >
> > data ParentsFlag = DontCreateParents | CreateParents
> >         deriving(Enum)
> >
> > now (toEnum . fromEnum) will convert between ParentsFlag and Bool.
>
> Ah, but imagine I don't have the module source handy.  Which
> corresponds to True and which to False?
>
> Mostly, I stay away from enumerations whose order matters, making a
> particular exception for Bool and Ord.
>
> If the names are (as above) DontDoSomething | DoSomething, using a
> newtype plus a boolean conveys the same sense without the
> forgetfulness:
>
> newtype CreateParents = CreateParents Bool
>
> createDirectory (CreateParents False)

Nice idea. Although this one also introduces additional global names, at 
least it is syntactically light-weight.

BTW, how about putting all these different ideas on the Haskell wiki?

Ben


More information about the Haskell-Cafe mailing list