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

Viktor Dukhovni ietf-dane at dukhovni.org
Mon Nov 20 20:57:40 UTC 2023


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.

-- 
    Viktor.


More information about the Haskell-Cafe mailing list