Multi Line String literals

Hello, Just for fun I'm trying to define multi line string literals. I have the following code and I'm wondering if it can be improved (understandability, elegance, performance): http://hpaste.org/1582 (look at the second annotation) regards, Bas van Dijk

On Thu, Apr 26, 2007 at 01:43:09PM +0100, Joe Thornber wrote:
On 26/04/07, Bas van Dijk
wrote: test = putStrLn $ toIsString $ do "I" "need" "MultiLine" "String" "literals!"
but it's simpler to just write something like:
test = putStr $ unlines ["I", "need", "multiline", "string", "literals"]
How does test = putStr "I\n\ \need\n\ \multiline\n\ \string\n\ \literals\n" look? Stefan

Hallo,
On 4/26/07, Neil Mitchell
Like the cpp will choke and die :) Multiline string literals were one of the motivations for cpphs.
Does cpphs allow me to include a whole file into a Haskell source file, inserting automatically the string gaps? -- -alex http://www.ventonegro.org/

Hallo,
On 4/26/07, Neil Mitchell
No, but Hugs does with "Here documents".
Unfortunately I'm using GHC but thanks! Cheers, -- -alex http://www.ventonegro.org/

Alex Queiroz
On 4/26/07, Neil Mitchell
wrote: Like the cpp will choke and die :) Multiline string literals were one of the motivations for cpphs.
Does cpphs allow me to include a whole file into a Haskell source file, inserting automatically the string gaps?
My hinstaller library certainly does. Though it currently allows you to only output that file to another file. I could easily improve it to allow output to a Handle. http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hinstaller Matthew

On 4/26/07, Joe Thornber
but it's simpler to just write something like:
test = putStr $ unlines ["I", "need", "multiline", "string", "literals"]
Yes I know. My aim was just to see if I could do it with as less syntax as possible and then the 'do' syntax is handy. Another question: If I change: type MLS = Writer (Endo [B.ByteString]) () instance IsString MLS where fromString s = tell $ Endo (fromString s:) instance ToString MLS where toString w = toString $ B.unlines $ (appEndo $ execWriter w) [] to the simpler: type MLS2 = Writer [B.ByteString] () instance IsString MLS2 where fromString s = tell [fromString s] instance ToString MLS2 where toString = toString . B.unlines . execWriter then MLS2 is a bit faster (about 0.4 sec. when applied to a million strings). I thought the former MLS should be faster because it doesn't have to mappend every [fromString s]. MLS just 'builds' a large function: "(fromString s:) . (fromString s:) . (fromString s:) ... id []" Can anybody explain why MLS2 is faster? Thanks, Bas van Dijk
participants (6)
-
Alex Queiroz
-
Bas van Dijk
-
Joe Thornber
-
Matthew Sackman
-
Neil Mitchell
-
Stefan O'Rear