How to escape double quotes in haskell?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite












I know that to escape special characters in Haskell we can use ", so if I try to pass as parameter:



parseString :: String
parseString = ""coord":["D","7"],"result":"HIT","prev":"coord":["A","10"],"result":null,"prev":null"


to the function



take 7 parseString


everything works fine, but I'm wondering is there are shorter way to produce the same result, without putting escape symbol " everywhere (imagine big JSON)?



For example, Python has this:



>>> s = """my string with "double quotes" blablabla"""
'my string with "double quotes" blablabla'









share|improve this question



















  • 1




    There are package that use Haskell's quasiquotes, to help produce raw strings.
    – Willem Van Onsem
    6 hours ago














up vote
6
down vote

favorite












I know that to escape special characters in Haskell we can use ", so if I try to pass as parameter:



parseString :: String
parseString = ""coord":["D","7"],"result":"HIT","prev":"coord":["A","10"],"result":null,"prev":null"


to the function



take 7 parseString


everything works fine, but I'm wondering is there are shorter way to produce the same result, without putting escape symbol " everywhere (imagine big JSON)?



For example, Python has this:



>>> s = """my string with "double quotes" blablabla"""
'my string with "double quotes" blablabla'









share|improve this question



















  • 1




    There are package that use Haskell's quasiquotes, to help produce raw strings.
    – Willem Van Onsem
    6 hours ago












up vote
6
down vote

favorite









up vote
6
down vote

favorite











I know that to escape special characters in Haskell we can use ", so if I try to pass as parameter:



parseString :: String
parseString = ""coord":["D","7"],"result":"HIT","prev":"coord":["A","10"],"result":null,"prev":null"


to the function



take 7 parseString


everything works fine, but I'm wondering is there are shorter way to produce the same result, without putting escape symbol " everywhere (imagine big JSON)?



For example, Python has this:



>>> s = """my string with "double quotes" blablabla"""
'my string with "double quotes" blablabla'









share|improve this question















I know that to escape special characters in Haskell we can use ", so if I try to pass as parameter:



parseString :: String
parseString = ""coord":["D","7"],"result":"HIT","prev":"coord":["A","10"],"result":null,"prev":null"


to the function



take 7 parseString


everything works fine, but I'm wondering is there are shorter way to produce the same result, without putting escape symbol " everywhere (imagine big JSON)?



For example, Python has this:



>>> s = """my string with "double quotes" blablabla"""
'my string with "double quotes" blablabla'






haskell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









duplode

21.7k44479




21.7k44479










asked 6 hours ago









savabe997

553




553







  • 1




    There are package that use Haskell's quasiquotes, to help produce raw strings.
    – Willem Van Onsem
    6 hours ago












  • 1




    There are package that use Haskell's quasiquotes, to help produce raw strings.
    – Willem Van Onsem
    6 hours ago







1




1




There are package that use Haskell's quasiquotes, to help produce raw strings.
– Willem Van Onsem
6 hours ago




There are package that use Haskell's quasiquotes, to help produce raw strings.
– Willem Van Onsem
6 hours ago












2 Answers
2






active

oldest

votes

















up vote
7
down vote



accepted










You escape double quotes with a backslash (" in a string), like:



""To be, or not to be" - William Shakespeare"


The above can of course be rather cumbersome in case you need to write a lot of double quotes. Haskell enables quasiquotes a way that is used by many Haskell packages to develop "mini-languages" inside Haskell. Quasiquotes are to the best of my knowledge not specified in the Haskell report, so it is not really a "Haskell feature", but the most popular compiler (GHC) supports this. A package like raw-strings-qq [Hackage] allows to make use of this feature to write raw strings, like:



-# LANGUAGE QuasiQuotes #-

import Text.RawString.QQ(r)

quote = [r|"To be, or not to be" - William Shakespeare|]


this thus produces strings like:



Prelude Text.RawString.QQ> [r|"To be, or not to be" - William Shakespeare|]
""To be, or not to be" - William Shakespeare"


QuasiQuotes are not only used to produce raw strings. In Yesod for example there are a few mini-languages to define HTML/CSS/JavaScript templates in Shakespearean languages (hamlet, lucius, cassius, julius). It is typically used if expressing something in "vanilla" Haskell would take a lot of work, whereas writing it in a specific language, makes it easier.






share|improve this answer





























    up vote
    7
    down vote













    Use ". There is no other way in vanilla Haskell. Eg:



    λ> putStrLn """
    "
    λ> putStrLn "my string with "double quotes" blablabla"
    my string with "double quotes" blablabla


    Further information on this can be very easily found in the Haskell 2010 Report (See §2.6 on character and string literals, particularly the definition of charesc.).



    However, by using Template Haskell, a metaprogramming system for Haskell, you can create raw strings. From the package page:



    λ> :set -XQuasiQuotes
    λ> import Text.RawString.QQ
    λ> let s = [r|w+@[a-zA-Z_]+?.[a-zA-Z]2,3|]
    λ> s
    "\w+@[a-zA-Z_]+?\.[a-zA-Z]2,3"
    λ> [r|C:WindowsSYSTEM|] ++ [r|user32.dll|]
    "C:\Windows\SYSTEM\user32.dll"


    Similarly you can type the strings above:



    λ> [r|my string with "double quotes" blablabla|]
    "my string with "double quotes" blablabla"


    Note that in Haskell source files this requires that you use the -# LANGUAGE QuasiQuotes #- pragma at the top of your file.






    share|improve this answer






















      Your Answer





      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52641516%2fhow-to-escape-double-quotes-in-haskell%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      7
      down vote



      accepted










      You escape double quotes with a backslash (" in a string), like:



      ""To be, or not to be" - William Shakespeare"


      The above can of course be rather cumbersome in case you need to write a lot of double quotes. Haskell enables quasiquotes a way that is used by many Haskell packages to develop "mini-languages" inside Haskell. Quasiquotes are to the best of my knowledge not specified in the Haskell report, so it is not really a "Haskell feature", but the most popular compiler (GHC) supports this. A package like raw-strings-qq [Hackage] allows to make use of this feature to write raw strings, like:



      -# LANGUAGE QuasiQuotes #-

      import Text.RawString.QQ(r)

      quote = [r|"To be, or not to be" - William Shakespeare|]


      this thus produces strings like:



      Prelude Text.RawString.QQ> [r|"To be, or not to be" - William Shakespeare|]
      ""To be, or not to be" - William Shakespeare"


      QuasiQuotes are not only used to produce raw strings. In Yesod for example there are a few mini-languages to define HTML/CSS/JavaScript templates in Shakespearean languages (hamlet, lucius, cassius, julius). It is typically used if expressing something in "vanilla" Haskell would take a lot of work, whereas writing it in a specific language, makes it easier.






      share|improve this answer


























        up vote
        7
        down vote



        accepted










        You escape double quotes with a backslash (" in a string), like:



        ""To be, or not to be" - William Shakespeare"


        The above can of course be rather cumbersome in case you need to write a lot of double quotes. Haskell enables quasiquotes a way that is used by many Haskell packages to develop "mini-languages" inside Haskell. Quasiquotes are to the best of my knowledge not specified in the Haskell report, so it is not really a "Haskell feature", but the most popular compiler (GHC) supports this. A package like raw-strings-qq [Hackage] allows to make use of this feature to write raw strings, like:



        -# LANGUAGE QuasiQuotes #-

        import Text.RawString.QQ(r)

        quote = [r|"To be, or not to be" - William Shakespeare|]


        this thus produces strings like:



        Prelude Text.RawString.QQ> [r|"To be, or not to be" - William Shakespeare|]
        ""To be, or not to be" - William Shakespeare"


        QuasiQuotes are not only used to produce raw strings. In Yesod for example there are a few mini-languages to define HTML/CSS/JavaScript templates in Shakespearean languages (hamlet, lucius, cassius, julius). It is typically used if expressing something in "vanilla" Haskell would take a lot of work, whereas writing it in a specific language, makes it easier.






        share|improve this answer
























          up vote
          7
          down vote



          accepted







          up vote
          7
          down vote



          accepted






          You escape double quotes with a backslash (" in a string), like:



          ""To be, or not to be" - William Shakespeare"


          The above can of course be rather cumbersome in case you need to write a lot of double quotes. Haskell enables quasiquotes a way that is used by many Haskell packages to develop "mini-languages" inside Haskell. Quasiquotes are to the best of my knowledge not specified in the Haskell report, so it is not really a "Haskell feature", but the most popular compiler (GHC) supports this. A package like raw-strings-qq [Hackage] allows to make use of this feature to write raw strings, like:



          -# LANGUAGE QuasiQuotes #-

          import Text.RawString.QQ(r)

          quote = [r|"To be, or not to be" - William Shakespeare|]


          this thus produces strings like:



          Prelude Text.RawString.QQ> [r|"To be, or not to be" - William Shakespeare|]
          ""To be, or not to be" - William Shakespeare"


          QuasiQuotes are not only used to produce raw strings. In Yesod for example there are a few mini-languages to define HTML/CSS/JavaScript templates in Shakespearean languages (hamlet, lucius, cassius, julius). It is typically used if expressing something in "vanilla" Haskell would take a lot of work, whereas writing it in a specific language, makes it easier.






          share|improve this answer














          You escape double quotes with a backslash (" in a string), like:



          ""To be, or not to be" - William Shakespeare"


          The above can of course be rather cumbersome in case you need to write a lot of double quotes. Haskell enables quasiquotes a way that is used by many Haskell packages to develop "mini-languages" inside Haskell. Quasiquotes are to the best of my knowledge not specified in the Haskell report, so it is not really a "Haskell feature", but the most popular compiler (GHC) supports this. A package like raw-strings-qq [Hackage] allows to make use of this feature to write raw strings, like:



          -# LANGUAGE QuasiQuotes #-

          import Text.RawString.QQ(r)

          quote = [r|"To be, or not to be" - William Shakespeare|]


          this thus produces strings like:



          Prelude Text.RawString.QQ> [r|"To be, or not to be" - William Shakespeare|]
          ""To be, or not to be" - William Shakespeare"


          QuasiQuotes are not only used to produce raw strings. In Yesod for example there are a few mini-languages to define HTML/CSS/JavaScript templates in Shakespearean languages (hamlet, lucius, cassius, julius). It is typically used if expressing something in "vanilla" Haskell would take a lot of work, whereas writing it in a specific language, makes it easier.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 5 hours ago









          chi

          69.4k278132




          69.4k278132










          answered 6 hours ago









          Willem Van Onsem

          127k16124207




          127k16124207






















              up vote
              7
              down vote













              Use ". There is no other way in vanilla Haskell. Eg:



              λ> putStrLn """
              "
              λ> putStrLn "my string with "double quotes" blablabla"
              my string with "double quotes" blablabla


              Further information on this can be very easily found in the Haskell 2010 Report (See §2.6 on character and string literals, particularly the definition of charesc.).



              However, by using Template Haskell, a metaprogramming system for Haskell, you can create raw strings. From the package page:



              λ> :set -XQuasiQuotes
              λ> import Text.RawString.QQ
              λ> let s = [r|w+@[a-zA-Z_]+?.[a-zA-Z]2,3|]
              λ> s
              "\w+@[a-zA-Z_]+?\.[a-zA-Z]2,3"
              λ> [r|C:WindowsSYSTEM|] ++ [r|user32.dll|]
              "C:\Windows\SYSTEM\user32.dll"


              Similarly you can type the strings above:



              λ> [r|my string with "double quotes" blablabla|]
              "my string with "double quotes" blablabla"


              Note that in Haskell source files this requires that you use the -# LANGUAGE QuasiQuotes #- pragma at the top of your file.






              share|improve this answer


























                up vote
                7
                down vote













                Use ". There is no other way in vanilla Haskell. Eg:



                λ> putStrLn """
                "
                λ> putStrLn "my string with "double quotes" blablabla"
                my string with "double quotes" blablabla


                Further information on this can be very easily found in the Haskell 2010 Report (See §2.6 on character and string literals, particularly the definition of charesc.).



                However, by using Template Haskell, a metaprogramming system for Haskell, you can create raw strings. From the package page:



                λ> :set -XQuasiQuotes
                λ> import Text.RawString.QQ
                λ> let s = [r|w+@[a-zA-Z_]+?.[a-zA-Z]2,3|]
                λ> s
                "\w+@[a-zA-Z_]+?\.[a-zA-Z]2,3"
                λ> [r|C:WindowsSYSTEM|] ++ [r|user32.dll|]
                "C:\Windows\SYSTEM\user32.dll"


                Similarly you can type the strings above:



                λ> [r|my string with "double quotes" blablabla|]
                "my string with "double quotes" blablabla"


                Note that in Haskell source files this requires that you use the -# LANGUAGE QuasiQuotes #- pragma at the top of your file.






                share|improve this answer
























                  up vote
                  7
                  down vote










                  up vote
                  7
                  down vote









                  Use ". There is no other way in vanilla Haskell. Eg:



                  λ> putStrLn """
                  "
                  λ> putStrLn "my string with "double quotes" blablabla"
                  my string with "double quotes" blablabla


                  Further information on this can be very easily found in the Haskell 2010 Report (See §2.6 on character and string literals, particularly the definition of charesc.).



                  However, by using Template Haskell, a metaprogramming system for Haskell, you can create raw strings. From the package page:



                  λ> :set -XQuasiQuotes
                  λ> import Text.RawString.QQ
                  λ> let s = [r|w+@[a-zA-Z_]+?.[a-zA-Z]2,3|]
                  λ> s
                  "\w+@[a-zA-Z_]+?\.[a-zA-Z]2,3"
                  λ> [r|C:WindowsSYSTEM|] ++ [r|user32.dll|]
                  "C:\Windows\SYSTEM\user32.dll"


                  Similarly you can type the strings above:



                  λ> [r|my string with "double quotes" blablabla|]
                  "my string with "double quotes" blablabla"


                  Note that in Haskell source files this requires that you use the -# LANGUAGE QuasiQuotes #- pragma at the top of your file.






                  share|improve this answer














                  Use ". There is no other way in vanilla Haskell. Eg:



                  λ> putStrLn """
                  "
                  λ> putStrLn "my string with "double quotes" blablabla"
                  my string with "double quotes" blablabla


                  Further information on this can be very easily found in the Haskell 2010 Report (See §2.6 on character and string literals, particularly the definition of charesc.).



                  However, by using Template Haskell, a metaprogramming system for Haskell, you can create raw strings. From the package page:



                  λ> :set -XQuasiQuotes
                  λ> import Text.RawString.QQ
                  λ> let s = [r|w+@[a-zA-Z_]+?.[a-zA-Z]2,3|]
                  λ> s
                  "\w+@[a-zA-Z_]+?\.[a-zA-Z]2,3"
                  λ> [r|C:WindowsSYSTEM|] ++ [r|user32.dll|]
                  "C:\Windows\SYSTEM\user32.dll"


                  Similarly you can type the strings above:



                  λ> [r|my string with "double quotes" blablabla|]
                  "my string with "double quotes" blablabla"


                  Note that in Haskell source files this requires that you use the -# LANGUAGE QuasiQuotes #- pragma at the top of your file.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited 6 hours ago

























                  answered 6 hours ago









                  AJFarmar

                  8,06722650




                  8,06722650



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52641516%2fhow-to-escape-double-quotes-in-haskell%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      Long meetings (6-7 hours a day): Being “babysat” by supervisor

                      Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                      Confectionery