concept guard in category haskell

This is an excerpt from Manning's book Get Programming with Haskell.
You can fix this issue by making it so that if one color is used to make another, combining them yields the composite color. So purple plus red is still purple. You could approach this problem by listing out a large number of pattern-matching rules comparing each possibility. But this solution would be long. Instead, you’ll use the Haskell feature called guards. Guards work much like pattern matching, but they allow you to do some computation on the arguments you’re going to compare. Figure 17.1 shows an example of a function using guards.
With an understanding of guards, you can rewrite your instance of Semigroup for Color so that you adhere to the type class laws for semigroups.
If you look at guard’s type signature, you find that it’s a strange function. Most notably, it has a type class constraint you haven’t seen before:
The Alternative type class is a subclass of Applicative (meaning all instances of Alternative must be instances of Applicative). But, unlike Applicative, Alternative isn’t a superclass of Monad; not all Monads are instances of Alternative. For the guard function, the key method of Alternative is empty, which works exactly like mempty from Monoid. Both List and Maybe are instances of Alternative. List’s empty value is [], and Maybe’s is Nothing. IO, however, isn’t an instance of Alternative. You can’t use guard with IO types.
When you first encounter guard, it might seem like magic. Surely, there must be some stateful mischief going on behind the scenes! Surprisingly, guard is a completely pure function. It’s far beyond the scope of this book, but if you feel comfortable with Monads, revisit guard and see whether you can implement it yourself. To understand guard, it helps tremendously to translate from do-notation back to >>=, >>, and lambdas. Learning about guard will also teach you a lot about the subtleties of >>. Again, this isn’t a particularly useful exercise for beginners, but highly recommended after you’re comfortable working with Monads.