Bracketless branch if, sugar to taste...

Yes indeed, one can further "sugar" Keith's suggestion to eliminate the need for brackets around the branches. Though as this means using an infix operator then and else, with corresponding mangling of the lexical appearance of same, this becomes increasingly a matter of taste (or perhaps, in need of sound dental advice). Example: ifM (return (1==1)) `then_` print (2+3) `else_` print (3+4) Of course, the type errors are going to start looking more and more mysterious if you get 'em in the wrong place... Cheers, Alex. ________ infix 4 `then_` infix 5 `else_` data Branches a = Branches a a then_ :: (a->a->a) -> Branches a -> a then_ sel (Branches t e) = sel t e else_ :: a->a->Branches a else_ t e = Branches t e iff b t e = if b then t else e ifM b t e = do test <- b if test then t else e
participants (1)
-
Alex Ferguson