[Haskell-cafe] Proposal: Generic conditions for 'if' and 'case'
Wvv
vitea3v at rambler.ru
Mon Sep 2 00:51:01 CEST 2013
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.
More information about the Haskell-Cafe
mailing list