Reputation: 127
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
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
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