[Haskell-cafe] Why does Haskell have the if-then-else syntax?
lemming at henning-thielemann.de
Thu Jul 27 04:57:20 EDT 2006
On Wed, 26 Jul 2006, Fritz Ruehr wrote:
> 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
> 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.
I found the argument order of the first if (Bool -> a -> a -> a) already
useful for a 'case' with computed conditions:
select = foldr (uncurry if_)
More information about the Haskell-Cafe