[Haskell-cafe] Why does Haskell have the if-then-else syntax?
Fritz Ruehr
fruehr at willamette.edu
Thu Jul 27 02:15:10 EDT 2006
On Jul 26, 2006, at 6:44 PM, Sebastian Sylvan wrote:
> For example ...
>
> if :: Bool -> a -> a -> a
> if True t _ = t
> if False _ e = e
>
> -- example usage
> myAbs x = if (x < 0) (negate x) x
I suppose there might also be a case for flipping the arguments about
like this:
if :: a -> a -> Bool -> a
if t _ True = t
if _ e False = e
This way it would follow foldr more closely, in recognition that the
conditional is essentially the fold/cata/eliminator/... for booleans.
But argument order is a pretty trivial thing, and I think the committee
made the right choice with if-then-else as a language construct.
-- Fritz
More information about the Haskell-Cafe
mailing list