Rohit
Rohit

Reputation: 127

Can I simplify the following Haskell lambda?

I want to simplify the following lambda using composition or some higher order magic,

(\a b -> if (b) then (not a) else a)

but I couldn't think of a clever way. Could you please help me out?

Thanks.

Upvotes: 3

Views: 237

Answers (2)

zcleghern
zcleghern

Reputation: 827

As another user pointed out, this is an example of xor, so how would we define this function?

If the inputs are equal, the result is false. If the inputs are not equal, the result is true.

\x y -> x /= y

Edit: The commentor is correct, my bad! The definition I gave previously does not work.

Upvotes: 3

luqui
luqui

Reputation: 60463

Let's look at the truth table:

   a    b      f
------------+------- 
False False | False
False True  | True
True  False | True
True  True  | False

That's interesting! f is True whenever the inputs are not the same. Hmm......

Upvotes: 12

Related Questions