From e09b406ee827a4256e56d02c3489697c57d7992e Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Mon, 21 Apr 2014 09:45:00 +0900 Subject: [PATCH] ToString String and doctest. --- Language/Haskell/GhcMod/Types.hs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Language/Haskell/GhcMod/Types.hs b/Language/Haskell/GhcMod/Types.hs index f2acf75..3e99e78 100644 --- a/Language/Haskell/GhcMod/Types.hs +++ b/Language/Haskell/GhcMod/Types.hs @@ -53,10 +53,33 @@ class ToString a where toLisp :: a -> String toPlain :: a -> String +-- | +-- +-- >>> toLisp "fo\"o" +-- "\"fo\\\"o\"\n" +-- >>> toPlain "foo" +-- "foo\n" +instance ToString String where + toLisp = addNewLine . quote + toPlain = addNewLine + +-- | +-- +-- >>> toLisp ["foo", "bar", "ba\"z"] +-- "(\"foo\" \"bar\" \"ba\\\"z\")\n" +-- >>> toPlain ["foo", "bar", "baz"] +-- "foo\nbar\nbaz\n" instance ToString [String] where toLisp = addNewLine . toSexp True toPlain = unlines +-- | +-- +-- >>> let inp = [((1,2,3,4),"foo"),((5,6,7,8),"bar")] :: [((Int,Int,Int,Int),String)] +-- >>> toLisp inp +-- "((1 2 3 4 \"foo\") (5 6 7 8 \"bar\"))\n" +-- >>> toPlain inp +-- "1 2 3 4 \"foo\"\n5 6 7 8 \"bar\"\n" instance ToString [((Int,Int,Int,Int),String)] where toLisp = addNewLine . toSexp False . map toS where @@ -72,7 +95,7 @@ tupToString ((a,b,c,d),s) = show a ++ " " ++ show b ++ " " ++ show c ++ " " ++ show d ++ " " - ++ quote s + ++ quote s -- fixme: quote is not necessary quote :: String -> String quote x = "\"" ++ escape x ++ "\""