or better yet i % 2 == 0
I think i % 2 is just straight up incorrect.
If we're talking about style, I think i % 2 == 0 is much more clear than (not i % 2). It says explicitly that the remainder of i divided by 2 is 0.
$ python3
>>> not 0
True
Python doesn't have Perl-like contexts, but it does treat lots of values as True or False. I do agree that i % 2 == 0
is more explicit here. if foo:
do_stuff()
over if len(foo) > 0:
do_stuff() class ExtendedBool t where
toBool :: t -> Bool
instance ExtendedBool Int where
toBool = (0/=)
instance ExtendedBool [a] where
toBool = not . null
if' v a b =
if (toBool v)
then a
else b
main = if' "String"
(print "True")
(print "False")