> > var1 = 2*2
> > var2 = 4*var1
> > var3 = "Foobar""
> > sqlstring = "insert into mytable values "++
> > "(NULL,'"++(show var1)++"','"++(show var2)++"','"++var3"');"
>
> It would be much nicer if Haskell did what perl,php, and tcl do:
> > sqlstring="insert into mytable values (NULL,'$var1','$var2','$var3')".
> Even nicer would be:
> > sqlstring="insert into mytable values
> (NULL,'$var1','$(var1+var2)','$var3')".
>
> (Notice both the embedded evaluation and the fact that the string runs
> accross multiple lines)
I agree that Haskell's string notation could be improved, but note that
you could write:
> sqlstring1 = "insert into mytable values \
> \(NULL,'"#var1++"','"#(var1+var2)++"','"++var3++"')"
which is pretty close to what you want, given the definition:
> (#) :: Show a => String -> a -> String
> s # a = s ++ show a
In particular, note that literal strings can be broken across lines
using the backslant character, and (of course) "embedded evaluation"
comes for free.
> PS Why does show string return quotation marks?
> It seems inconsistent.
show x should be a string that when printed looks like the value that
you would have to type to generate it directly. This example is most
instructive:
data Foo = Foo
deriving Show
show Foo ==> "Foo"
show (show Foo) ==> show ("Foo") ==> "\"Foo\""
show (show (show Foo)) ==> show ("\"Foo\"") ==> "\"\\\"Foo\\\"\""
etc. This is actually quite consistent.
-Paul