, -XRebindableSyntax ( ):
{-# LANGUAGE RebindableSyntax #-}
module Test where
import qualified Prelude as P
class Decidable b where
toBool :: b -> P.Bool
instance Decidable P.Bool where
toBool = P.id
ifThenElse :: Decidable b => b -> a -> a -> a
ifThenElse b ifTrue ifFalse = case toBool b of
P.True -> ifTrue
P.False -> ifFalse
data Test = A | B deriving (P.Eq, P.Show)
instance Decidable Test where
toBool A = P.True
toBool B = P.False
GHCi:
> :l decidable.hs
> :set -XRebindableSyntax
> P.putStrLn (if A then "it worked!" else "it failed!")
it worked!
, ! , - , , , .