Boolean implies another

375 views Asked by At

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".

2

There are 2 answers

0
Mikaël Mayer On BEST ANSWER

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

Edit I also found Dafny and probably most other mathematical languages:

print true ==> false;

false
0
Paul King On

Another language which supports this is Groovy (from version 5.0.0-alpha-4):

groovy:000> true ==> false
===> false
groovy:000> false ==> throw new Exception('Boom!')
===> true