On Tue, May 24, 2005 at 02:31:29PM -0400, robert dockins wrote:
> 
> >>> 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"

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.

        John



-- 
John Meacham - ⑆repetae.net⑆john⑈ 
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to