0

Is there a programming language in which we can write something like:

a => b

to compute implication? (where a and b are booleans)

The closest I can find is in Scala:

a <= b

But it looks completely different from the actual meaning of "implication".

Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
  • If you're interested in a Boolean expression for `a -> b`, then you can use that fact that it is "true table equivalent" to `(not a) or b`. So in `C`, the equivalent of `a -> b` would be, `!a || b`. – lurker Jan 04 '14 at 20:20
  • yes, I know this fact. But it is not as nice as something like an arrow. – Mikaël Mayer Jan 04 '14 at 20:21
  • 2
    Procedural languages I know of don't have an explicit `a -> b` as it wouldn't really add a lot of value as a "pure logical expression". Ultimately, the programmer would really mean `(not a) or b` if they're looking for that type of truth value, and it's more understandable. Of course, `if-then` statements occur all the time procedurally and, therefore, are ubiquitous (I realize that's not the same thing). Prolog has an implication (`->`), but it's not quite the same as a boolean expression of other languages. – lurker Jan 04 '14 at 20:25
  • I don't agree with the fact that this would not add value to the logical expressions. I asked this question because I sometimes face logical expressions which would be more meaningful if I wrote them using arrows than (not a) or b. In my case, `if((condition1 => condition2) && (!condition1 => condition3)) statement` looks better than `if((!condition1 || condition2) && (condition1 || condition3)) statement` – Mikaël Mayer Jan 04 '14 at 20:38
  • 1
    In C++ you can define an operator and make it work that way. I only say it's "limited use" because if I see `if (A => B)` in code, in my mind I'd be translating it into `(not A) or B` to figure out what it does. But that's because I'm not used to thinking that "false implies true" is true. And it's fairly brief to write `!A || B` versus `A => B` so the motivation to introduce a new operator isn't high. At least I'd speculate that's why it's not prevalent in procedural languages (and possibly to avoid confusion with actual procedural `if-then` constructs). – lurker Jan 04 '14 at 20:45

1 Answers1

0

So the winner is Scala:

implicit class BooleanMagic(val b: Boolean) extends AnyVal {
  def ==>(other: =>Boolean) = !b || other
}

Thanks to that:

> true ==> false
res0: Boolean = false

> false ==> (throw new Exception("I'm the president"))
res1: Boolean = true
Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101