I would like to remove the if ... then ... else ...
keywords, because I am embedding a language/DSL in Haskell. if
, then
and else
convey a lot of meaning in many domains, and it would be great if I could redefine (or leave them undefined) them to reflect the nature of the language/domain.
I've searched on Google and stackoverflow, but found nothing. (I did find an old thread on why if ... then ... else ...
was included as keywords in Haskell.)
My IDE is in Leksah, and, if the keywords can be removed, it would also be nice to have a setting to change the if ... then ... else ...
keywords back to their normal font/color/unbold.
I've already tried a naming convention of if'
for if
and so on. It doesn't feel as good, especially when I want to define if
and if'
, and have to define if'
and if''
instead, or if1
and if2
. The presence of both if'
and if
might also be confusing. (The confusion is not that serious an issue in my situation as the users of the DSL are Haskell programmers, but I suppose it can help in other situations).
Summarizing the responses to date:
- Use the
RebindableSyntax
extension to GHC. Not as general as removing the keywords: the syntax of Haskell's if-then-else is retained. (Frerich Raabe) - Workaround: Use very similar words/names, by using
data Conditional b a = If b (Then a) (Else a)
(only applicable in some contexts). (C. A. McCann)
If RebindableSyntax
is a relatively new feature, then it's unlikely to find a more general way, at least not till the next version of GHC.
data Conditional b a = If b (Then a) (Else a)
. – Dry