[Haskell-cafe] APIs
Jan-Willem Maessen
jmaessen at alum.mit.edu
Tue May 24 18:11:58 EDT 2005
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)
-Jan-Willem Maessen
More information about the Haskell-Cafe
mailing list