[Haskell-cafe] A useful trick for inclusion and exclusion of commented code

Wolfgang Jeltsch wolfgang at jeltsch.net
Mon Apr 12 13:39:09 EDT 2004


Am Sonntag, 11. April 2004 23:14 schrieb Sunil KOTHARI:
> Here's a little trick that I often use for inclusion and exclusion of
> a chunk of code.
> Imagine we have  a  function foo defined below.
> The three lines of code  can be included
> or excluded  just by a changing a single character --- that's the trick.
> So, the idea is to comment our code in a slightly different way like
> this to exclude the code from executing:
> 1 {-
> 2 myand :: Bool -> Bool -> Bool
> 3 myand a b = if a == b then True
> 4                      else False
> 5 --}
>
> Notice how line  5 is commented '--}' instead of '-}'. Now, if we change
> the first character in line 11 from '{' to '-' the entire chunk of code
> from line 12-14 no longer remains comment.
>
> 11 --
> 12 myand :: Bool -> Bool -> Bool
> 13 myand a b = if a == b then True
> 14                      else False
> 15 --}
>
> This trick can also be applied to C++ comments.
>
> Best wishes,
> Sunil

Hello,

does this trick also work with GHC?  I think that GHC needs a space after -- 
if these two dashes shall introduce an one line comment.

Wolfgang



More information about the Haskell-Cafe mailing list