4 ms·
I don't think this is a good idea. If you have a `ToBool` instance it should really do the right thing in all circumstances. And this doesn't: if the `Int` in
by mooism2 13y ago
I don't think this is a good idea. If you have a `ToBool` instance it should really do the right thing in all circumstances.
And this doesn't: if the `Int` in question is the exit status of a process, then 0 should be truthy and everything else falsy.
Better to make the test explicit. If the test is at all complex you wrap it up in its own function anyway, so it's not like it makes the if expression harder to read.
Consider also the instance for `Maybe`: which of these is right?
instance ToBool (Maybe a) where
toBool = isJust
instance ToBool a => ToBool (Maybe a) where
toBool = maybe False toBool
- eru 13y agoI agree with you. I just wanted to point out, that the relaxed booleans do not have to be a property of the language, but can be done in a library. (Hey, even `if' could be a library function in Haskell. (And really, should be.))
- mooism2 13y agoYou also have to supply alternatives to && || and not; that still leaves functions (e.g. filter) and constructors with Boolean parameters. Whether you're fighting the language or the standard library is a moot point: you're fighting it instead of working with it.
- eru 13y ago> You also have to supply alternatives to && || and not; that still leaves functions (e.g. filter) and constructors with Boolean parameters. There's some lifting approaches that construct those functions mostly automatically for you, as wrappers around the base functions on Booleans.
- tormeh 13y agoYes, but then you're relying on pattern-matching to define if. PM is not better than if, it's just different.