DEV Community

Ken Aguilar
Ken Aguilar

Posted on

Haskell - Boolean Blindness == True

What does the title even mean? True? for what? Good? Bad? Useful? If it was False, would we see any meaning?

Even the state of a light bulb cannot be properly represented by booleans. Would True mean the light is on? or would it mean off?

What if the decision on whether Boolean Blindess is bad or good is represented with a sum type

data Decision 
  = Bad
  | Good
  deriving Show

makeDecision :: Decision -> Text
makeDecision decision = case decision of
  Bad -> "Boolean blindness is " <> ( show Bad ) <> "!"
  Good -> "Boolean blindess is " <> ( show Good ) <> "!"

I think using the sum type gives it meaning. Now we can make a decision about Boolean Blindess.

I lessen confusion in my code by using booleans conservatively.

Top comments (2)

Collapse
 
tfausak profile image
Taylor Fausak

Well said! I'm convinced that booleans should almost never be used. An explicit type makes things both easier to understand and harder to misuse.

Collapse
 
shimmer profile image
Brian Berns

Would True mean the light is on? or would it mean off?

Hmm, can't say I agree with this one. I'm pretty sure all reasonable people would agree that True = On.