multiline strings in haskell?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

multiline strings in haskell?

Michael Vanier
Is there any support for multi-line string literals in Haskell?  I've
done a web search and come up empty.  I'm thinking of using Haskell to
generate web pages and having multi-line strings would be very useful.

Mike

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: multiline strings in haskell?

Michael Vanier
Yes, just like that ;-)  Thanks!

Now if somebody has a string interpolation library, I'd be a pretty
happy camper ;-)

Mike


> mvanier:
>> Is there any support for multi-line string literals in Haskell?  I've
>> done a web search and come up empty.  I'm thinking of using Haskell to
>> generate web pages and having multi-line strings would be very useful.
>
> Do you mean like this:
>
>     string = "     line one\n\
>              \   line two is here\n\
>              \   line three is this line\n"
>
>
> $ echo 'putStr string' | ghci A.hs
>      line one
>    line two is here
>    line three is this line
>
> -- Don
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: multiline strings in haskell?

Donald Bruce Stewart
Oh, like this (by Stefan Wehr):
    http://www.cse.unsw.edu.au/~dons/code/icfp05/tests/unit-tests/VariableExpansion.hs   

$ ghci -fth VariableExpansion.hs
*VariableExpansion> let x = 7 in $( expand "${x}" )
"7"
*VariableExpansion> let url = "http://www.google.com"
*VariableExpansion> $( expand "Here is my url: ${url}. Do you like it?" )
"Here is my url: \"http://www.google.com\". Do you like it?"

Cheers,
  Don

mvanier:

> Yes, just like that ;-)  Thanks!
>
> Now if somebody has a string interpolation library, I'd be a pretty
> happy camper ;-)
>
> Mike
>
>
> >mvanier:
> >>Is there any support for multi-line string literals in Haskell?  I've
> >>done a web search and come up empty.  I'm thinking of using Haskell to
> >>generate web pages and having multi-line strings would be very useful.
> >
> >Do you mean like this:
> >
> >    string = "     line one\n\
> >             \   line two is here\n\
> >             \   line three is this line\n"
> >
> >
> >$ echo 'putStr string' | ghci A.hs
> >     line one
> >   line two is here
> >   line three is this line
> >
> >-- Don
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: multiline strings in haskell?

Michael Vanier
Excellent! Thanks.

Mike

Donald Bruce Stewart wrote:

> Oh, like this (by Stefan Wehr):
>     http://www.cse.unsw.edu.au/~dons/code/icfp05/tests/unit-tests/VariableExpansion.hs   
>
> $ ghci -fth VariableExpansion.hs
> *VariableExpansion> let x = 7 in $( expand "${x}" )
> "7"
> *VariableExpansion> let url = "http://www.google.com"
> *VariableExpansion> $( expand "Here is my url: ${url}. Do you like it?" )
> "Here is my url: \"http://www.google.com\". Do you like it?"
>
> Cheers,
>   Don
>
> mvanier:
>> Yes, just like that ;-)  Thanks!
>>
>> Now if somebody has a string interpolation library, I'd be a pretty
>> happy camper ;-)
>>
>> Mike
>>
>>
>>> mvanier:
>>>> Is there any support for multi-line string literals in Haskell?  I've
>>>> done a web search and come up empty.  I'm thinking of using Haskell to
>>>> generate web pages and having multi-line strings would be very useful.
>>> Do you mean like this:
>>>
>>>    string = "     line one\n\
>>>             \   line two is here\n\
>>>             \   line three is this line\n"
>>>
>>>
>>> $ echo 'putStr string' | ghci A.hs
>>>     line one
>>>   line two is here
>>>   line three is this line
>>>
>>> -- Don
>> _______________________________________________
>> Haskell-Cafe mailing list
>> [hidden email]
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: multiline strings in haskell?

Henning Thielemann
In reply to this post by Michael Vanier

On Wed, 11 Jan 2006, Michael Vanier wrote:

> Is there any support for multi-line string literals in Haskell?  I've
> done a web search and come up empty.  I'm thinking of using Haskell to
> generate web pages and having multi-line strings would be very useful.

Do you mean

unlines ["first line", "second line", "third line"]

?

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: multiline strings in haskell?

Jason Dagit

On Jan 12, 2006, at 1:34 AM, Henning Thielemann wrote:

>
> On Wed, 11 Jan 2006, Michael Vanier wrote:
>
>> Is there any support for multi-line string literals in Haskell?  I've
>> done a web search and come up empty.  I'm thinking of using  
>> Haskell to
>> generate web pages and having multi-line strings would be very  
>> useful.
>
> Do you mean
>
> unlines ["first line", "second line", "third line"]

The original poster probably meant something like this:

let foo = "This is a
long string


Which does not end until the matching end quote."

Common Lisp has strings like this.  Quite convenient whenever you're  
communicating using lots of strings of data.  For example, when  
running as a cgi script.

Thanks,
Jason

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: multiline strings in haskell?

Henning Thielemann

On Thu, 12 Jan 2006, Jason Dagit wrote:

> On Jan 12, 2006, at 1:34 AM, Henning Thielemann wrote:
>
> > On Wed, 11 Jan 2006, Michael Vanier wrote:
> >
> >> Is there any support for multi-line string literals in Haskell?  I've
> >> done a web search and come up empty.  I'm thinking of using
> >> Haskell to
> >> generate web pages and having multi-line strings would be very
> >> useful.
> >
> > Do you mean
> >
> > unlines ["first line", "second line", "third line"]
>
> The original poster probably meant something like this:
>
> let foo = "This is a
> long string
>
>
> Which does not end until the matching end quote."

I don't see the need for it, since

unlines [
  "first line",
  "second line",
  "third line"]

works as well.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: multiline strings in haskell?

Sebastian Sylvan
On 1/12/06, Henning Thielemann <[hidden email]> wrote:

>
> On Thu, 12 Jan 2006, Jason Dagit wrote:
>
> > On Jan 12, 2006, at 1:34 AM, Henning Thielemann wrote:
> >
> > > On Wed, 11 Jan 2006, Michael Vanier wrote:
> > >
> > >> Is there any support for multi-line string literals in Haskell?  I've
> > >> done a web search and come up empty.  I'm thinking of using
> > >> Haskell to
> > >> generate web pages and having multi-line strings would be very
> > >> useful.
> > >
> > > Do you mean
> > >
> > > unlines ["first line", "second line", "third line"]
> >
> > The original poster probably meant something like this:
> >
> > let foo = "This is a
> > long string
> >
> >
> > Which does not end until the matching end quote."
>
> I don't see the need for it, since
>
> unlines [
>   "first line",
>   "second line",
>   "third line"]
>
> works as well.
>

Nevertheless Haskell supports multiline strings (although it seems
like a lot of people don't know about it). You escape it using \ and
then another \ where the string starts again.

str = "multi\
        \line"

Prelude>str
"multiline"


/S

--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe