daniel.is.fischer at web.de
Tue May 24 19:09:19 EDT 2005
Am Mittwoch, 25. Mai 2005 00:46 schrieb Benjamin Franksen:
> 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?
What about a type synonym? I think
type CreateParents = Bool
wouldn't be a bad solution, you can directly use boolean operations and the
name makes clear what True and False mean.
More information about the Haskell-Cafe