[Haskell-cafe] Folded long string literals and CPP?

Viktor Dukhovni ietf-dane at dukhovni.org
Tue Nov 21 03:29:11 UTC 2023


On Mon, Nov 20, 2023 at 03:57:40PM -0500, Viktor Dukhovni wrote:

> On Mon, Nov 20, 2023 at 03:07:42PM -0500, Viktor Dukhovni wrote:
> > 
> > I may have found an acceptable  work-around:
> > 
> >     {-# LANGUAGE CPP #-}
> >     module Main(main) where
> > 
> >     hello :: String
> >     hello = "Hello\ \
> >             \ World!"
> > 
> >     main :: IO ()
> >     main = print hello
> > 
> > Is this trick "well known"?
> 
> I have now (should have earlier) checked the user guide and found:
> 
>     https://downloads.haskell.org/ghc/latest/docs/users_guide/phases.html?highlight=string%20gaps#cpp-and-string-gaps
> 
> and see that the it suggests adding trailing spaces.  If that once
> worked, it no longer seems to.  However adding a space and a trailing
> "\" does work.  Perhaps the documentation can be updated?
> 
> I do not know how portable my "\ \" sufix is across various systems.  It
> works on a Fedora 36 system (Gnu toolchain), and with FreeBSD with both
> Clang and Gnu CPP.

FWIW, GitHub CI shows that ending lines with "\ \" works on Ubuntu,
MacOS and Windows.  So it looks reasonably portable.

The main downside is that the source code has to be changed when adding
or removing "CPP", that would not have been the case with just "\ ", but
that sadly does not work in practice. :-(

-- 
    Viktor.


More information about the Haskell-Cafe mailing list