I didn't test it, but you might want to look into the 'rebindable syntax' extension and its 'ifThenElse' feature.

Nicolas

On Sep 2, 2013 12:51 AM, "Wvv" <vitea3v@rambler.ru> wrote:
I think it is an old idea, but nevertheless.
Now we have next functions:

if (a :: Bool) then x else y

case b of
a1 :: Bool -> x1
a2 :: Bool -> x2
...

Let we have generic conditions for 'if' and 'case':

class Boolean a where
    toBool :: a -> Bool

instance Boolean Bool where
   toBool = id

instance Boolean [a] where
   toBool [] = False
   toBool _ = True

instance Boolean (Maybe a) where
   toBool Nothing = False
   toBool _ = True

instance Boolean Int where
   toBool 0 = False
   toBool _ = True

if' (a :: Boolean b) then x else y

case' d of
a1 :: Boolean b1 -> x1
a2 :: Boolean b2 -> x2
...


It is very easy to implement to desugar:
if' a then ... == if toBool ( a ) then ...



--
View this message in context: http://haskell.1045720.n5.nabble.com/Proposal-Generic-conditions-for-if-and-case-tp5735366.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe