[Haskell-cafe] Bool is not...safe?!

Olaf Klinke olf at aatal-apotheke.de
Thu Jul 5 20:26:59 UTC 2018

Indeed, why use Bool when you can have your own algebraic datatype? Why not 

data Equality = Equal | NotEqual
(==) :: Eq a => a -> a -> Equality

when we have essentially the same for 'compare' already? Why not use

data Result = Success | Failure

as the return type of effectful code? Equality and Result are Booleans with some provenance. 
But wait! Equality does not come with all the nice functions like (||) and (&&), and Failure still does not tell us what exactly went wrong. Maybe a derivable type class IsomorphicToBool could remedy the former problem. For the latter, Haskell has exception monads. One of the things I love about Haskell is that I do not have to use Int as a return type and remember that negative numbers mean failure of some sort, or worse, the return type is Void but some global variable may now contain the error code of the last function call. In some post in haskell-cafe which I am unable to find right now it was mentioned that the GHC source contains many types that are isomorphic but not equal to Bool. 
Does anyone know whether the C and C++ folks are now using more informative structs as return types? 


More information about the Haskell-Cafe mailing list