Legitimate use of Boolean vs newtype (evidence)

I was reading this blog article about boolean blindness and was left thinking about situations where I’ve written functions like isX :: a -> Bool.

One case where it’s useful is for filtering which easily takes functions such as these. However, according to the evidence pattern, would it then be preferable to catMaybes . map prime?

Yes, or mapMaybe prime.

4 Likes

If you push the argument to the limit, you’ll remove the Bool type all together. Which mean removing function like filter but also even if ... then construct (you can pattern match instead). I don’t think this is realistic.

I think newtypes make sense for function arguments if the function name don’t make it clear (and there is a real blindspot), but less for function names where the semantic should be self explanatory.

2 Likes

One case where it’s useful is for filtering which easily takes functions such as these. However, according to the evidence pattern, would it then be preferable to catMaybes . map prime ?

That is actually mentioned in the “learning by testing” episode of The Haskell Unfolder.

1 Like