# How bad is it if x \< y doesn't return a Bool?

**URL:** <https://discourse.julialang.org/t/how-bad-is-it-if-x-y-doesnt-return-a-bool/114611>\
**Category:** General Usage\
**Tags:** method-invalidation, type-piracy\
**Created:** [May 23, 2024, 7:52am UTC](https://discourse.julialang.org/t/how-bad-is-it-if-x-y-doesnt-return-a-bool/114611 "2024-05-23T07:52:41Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [May 23, 2024, 11:25am UTC](https://discourse.julialang.org/t/how-bad-is-it-if-x-y-doesnt-return-a-bool/114611/21 "2024-05-23T11:25:50Z")

</div>

Then that’s probably the solution you’ll have to go for. It’s just important to make sure that everyone is aware that this kind of approach explicitly goes outside of the semantics the original user code was written under. It’s not a general solution for arbitrary code.

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [May 23, 2024, 2:13pm UTC](https://discourse.julialang.org/t/how-bad-is-it-if-x-y-doesnt-return-a-bool/114611/22 "2024-05-23T14:13:23Z")

</div>

If the point of this is to work for user code, how do you hope to handle actually-branching code like `x < y ? x : y`, `if`/`else`, or non-independent `for`/`while`? Is actual control flow explicitly unsupported? What about “boolean arithmetic” like `x *= (x > 0)`? None of those seem compatible with non-Bool comparison.

I imagine `ifelse(x < y, x, y)` is merely a MWE, but it does suggest that you need to overload `min`/`max` among your other functions.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/224680_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [May 24, 2024, 6:30am UTC](https://discourse.julialang.org/t/how-bad-is-it-if-x-y-doesnt-return-a-bool/114611/23 "2024-05-24T06:30:27Z")

</div>

> [@mikmoore](#):
>
> If the point of this is to work for user code, how do you hope to handle actually-branching code like `x < y ? x : y`, `if`/`else`, or non-independent `for`/`while`? Is actual control flow explicitly unsupported?

Yes, that kind of control flow would try to cast `x < y` as a `Bool` and thus error. In such cases however, `ifelse` will work.

> [@mikmoore](#):
>
> What about “boolean arithmetic” like `x *= (x > 0)`?

This however will be supported, because we settled on a design where the return of `x < y` is also a `Number`.

[Previous page](https://discourse.julialang.org/t/how-bad-is-it-if-x-y-doesnt-return-a-bool/114611.md?page=1)
