[Haskell-cafe] Lambda-case / lambda-if

Henning Thielemann lemming at henning-thielemann.de
Sat Oct 2 14:35:52 EDT 2010


On Sat, 2 Oct 2010, Colin Paul Adams wrote:

>>>>>> "Max" == Max Bolingbroke <batterseapower at hotmail.com> writes:
>
>    Prelude> (if then "Haskell" else "Cafe") False
>    Max> "Cafe"
>
> My reaction is to ask:
>
> Can you write this as:
>
> (if then else) False  "Haskell"  "Cafe"
>
> ?

Sure:

ifThenElse :: Bool -> a -> a -> a
ifThenElse True  x _ = x
ifThenElse False _ y = y

Prelude> ifThenElse False "Haskell" "Cafe"

(I have done this in utility-ht, and called it "if'".)


More information about the Haskell-Cafe mailing list