[Haskell-cafe] if-then-else as rebindable syntax (was Re: Why
does Haskell have the if-then-else syntax?)
niklas.broberg at gmail.com
Thu Jul 27 12:03:56 EDT 2006
On 7/27/06, David House <dmhouse at gmail.com> wrote:
> How about we drop the idea of an auxilary cond function, and instead
> just use a Boolean typeclass?
> class Boolean b where
> isTrue :: b -> Bool
> isFalse :: b -> Bool
> Then the semantics of if-then-else would change to something like this:
> if b then t1 else t2
> b is required to be of a type which instantiates Boolean
> If isTrue b is True, then t1 is executed, otherwise if isFalse b is
> True, then t2 is executed, otherwise _|_ is returned.
> Then you get the benefit of being able to use arbitrary 'boolean-like'
> types in actual if statements, without messing around with
> -fno-implicit-prelude and rebindable syntax.
It would be possible, sure, but I don't want to go in this direction.
I don't only want to overload the if-then-else for different kinds of
booleans, I would like to be able to change its behavior completely.
One particular application of this that I have in mind is the
his SoC project. There the "embedding" is actually a set of
combinators for constructing an abstract syntax tree, so if-then-else
would translate into the data constructor IfThenElse applied to its
More information about the Haskell-Cafe