DEV Community

Discussion on: If/else or just if?

pedrohba1 profile image
Pedro Bufulin

The first time I heard the term "guard" was in haskell. Is it any related?

somedood profile image
Basti Ortiz

I'm quite surprised actually. Given the imperative nature of if statements, I wouldn't expect Haskell (of all languages) to be the origin of that term.

Thread Thread
fennecdjay profile image
Jérémie Astor

Haskell (among other functional languages, I guess) has guards for pattern matching

sign x |  x >  0        =   1
       |  x == 0        =   0
       |  x <  0        =  -1