Skip to main content
Tweeted twitter.com/StackMma/status/976374593983340544
edited tags
Link
Source Link
Michael Stern
  • 4.7k
  • 1
  • 21
  • 37

why doesn't this work to screen for Boolean inputs?

I routinely sanitize the inputs to a function using this sort of technique:

funcI[x_Integer] := Print[x];

But it doesn't work with Booleans.

func[x_Boolean] := Print[x];

func[4] (* doesn't execute, as expected *)

func[True] (* doesn't execute, but it should, right? *)

As a workaround, I can use func2[x_ /; BooleanQ[x]] := Print[x];, but why doesn't the simpler formulation work?

func2[True] (* works just fine *)