Just a quick post as I've not had a lot of time to play with Haskell just recently.
This morning I noticed Jonathan Lang's post to perl6-language asking if the
ternary operator ?? !! could be turned into two binary operators. I thought
this had been discussed some time back, but apparently not. Audrey commented that
his suggested solution might not work for cases where the condition is true but the result value is untrue. I wondered if Perl 6's "hypothetical variables"
(which might or might not contain a value) could be used. In that case, you could
make ?? bind the hypothetical variable if the Left Hand Side is true, and not otherwise.
!! would then become one of the list of short-circuiting OR operators.
|| # truth // # definedness !! # "boundness"
I then had a snap of inspiration that it could be done in Haskell with the Maybe
monad and knocked up the following (using ? ! because !! is already taken for
True ? a = Just a False ? _ = Nothing Just a ! _ = a Nothing ! b = b
Which seems to give the expected results
*Main> True ? "Bill" ! "Ben""Bill"*Main> False ? "Bill" ! "Ben""Ben"