Operators in JavaScript and Haskell

  • And and Or (Booleans)
  • Not (Booleans)
  • Or (Maybe)
  • And (Maybe)
  • Ternary conditional
  • 8 minutes
Bool Maybe Alternative Applicative

JavaScript has a handful of builtin infix operators and some convenient tricks you can do with them. Here we look at what you can do with those operators, and how you can do the same things in Haskell.

  1. The basic Boolean operators &&, ||, and ! look much the same between the two languages.
  2. It gets more interesting when we consider what it means in JavaScript to use && and || with things that aren’t Booleans; we’ll see what operators work with the Maybe type to us do similar things in Haskell.
  3. JavaScript has both if-else blocks and the “ternary” ?-: operator; Haskell’s if-then-else plays the role of both of these.