[Haskell-cafe] if-then-else as rebindable syntax (was Re: Why
does Haskell have the if-then-else syntax?)
David House
dmhouse at gmail.com
Thu Jul 27 11:52:44 EDT 2006
On 27/07/06, David Roundy <droundy at darcs.net> wrote:
> Or perhaps (?:) or something like that, which could be used infix to
> evoke the idea of C's e1 ? e2 : e3 syntax. "provided" to me is less
> clear than "cond" since it has other meanings, and isn't borrowed from
> any language that I'm familiar with, like "cond" is.
This has come up a few times on #haskell, and the consensus is that a
tertiary (?:) operator isn't possible because of the deep specialness
of (:). However, you can simulate it pretty well:
infixr 1 ?
(?) :: Bool -> (a, a) -> a
True ? (t, _) = t
False ? (_, t) = t
Then you call it like:
length "hello" > 4 ? ("yes it is!", "afraid not")
--
-David House, dmhouse at gmail.com
More information about the Haskell-Cafe
mailing list