Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve formatting of code examples

  • Loading branch information...
commit 4866c6ced08d59408ebed13c0b35c6413100c25f 1 parent c2e0c41
@tibbe authored
Showing with 51 additions and 60 deletions.
  1. +7 −10 Data/Csv.hs
  2. +44 −50 Data/Csv/Conversion.hs
View
17 Data/Csv.hs
@@ -86,9 +86,8 @@ import Data.Csv.Types
--
-- A short encoding usage example:
--
--- @ >>> 'encode' $ fromList [(\"John\" :: Text, 27), (\"Jane\", 28)]
--- Chunk \"John,27\\r\\nJane,28\\r\\n\" Empty
--- @
+-- > >>> encode $ fromList [("John" :: Text, 27), ("Jane", 28)]
+-- > Chunk "John,27\r\nJane,28\r\n" Empty
--
-- Since string literals are overloaded we have to supply a type
-- signature as the compiler couldn't deduce which string type (i.e.
@@ -98,9 +97,8 @@ import Data.Csv.Types
--
-- A short decoding usage example:
--
--- @ >>> 'decode' 'False' \"John,27\\r\\nJane,28\\r\\n\" :: Either String (Vector (Text, Int))
--- Right (fromList [(\"John\",27),(\"Jane\",28)])
--- @
+-- > >>> decode False "John,27\r\nJane,28\r\n" :: Either String (Vector (Text, Int))
+-- > Right (fromList [("John",27),("Jane",28)])
--
-- We pass 'False' as the first argument to indicate that the CSV
-- input data isn't preceded by a header.
@@ -116,9 +114,8 @@ import Data.Csv.Types
-- parse a CSV file to a generic representation, just convert each
-- record to a @'Vector' 'ByteString'@ value, like so:
--
--- @ 'decode' 'False' \"John,27\\r\\nJane,28\\r\\n\" :: Either String (Vector (Vector ByteString))
--- Right (fromList [fromList [\"John\",\"27\"],fromList [\"Jane\",\"28\"]])
--- @
+-- > decode False "John,27\r\nJane,28\r\n" :: Either String (Vector (Vector ByteString))
+-- > Right (fromList [fromList ["John","27"],fromList ["Jane","28"]])
--
-- As the example output above shows, all the fields are returned as
-- uninterpreted 'ByteString' values.
@@ -144,7 +141,7 @@ import Data.Csv.Types
--
-- > case decode False "0xff,0xaa\r\n0x11,0x22\r\n" of
-- > Left err -> putStrLn err
--- > Right v -> V.forM_ v $ \ (Hex val1, Hex val2) ->
+-- > Right v -> forM_ v $ \ (Hex val1, Hex val2) ->
-- > print (val1, val2)
View
94 Data/Csv/Conversion.hs
@@ -81,15 +81,14 @@ import qualified Data.IntMap as IM
--
-- here's an example type and instance:
--
--- @data Person = Person { name :: Text, age :: Int }
---
--- instance FromRecord Person where
--- parseRecord v
--- | 'V.length' v == 2 = Person '<$>'
--- v '.!' 0 '<*>'
--- v '.!' 1
--- | otherwise = mzero
--- @
+-- > data Person = Person { name :: Text, age :: Int }
+-- >
+-- > instance FromRecord Person where
+-- > parseRecord v
+-- > | length v == 2 = Person <$>
+-- > v .! 0 <*>
+-- > v .! 1
+-- > | otherwise = mzero
class FromRecord a where
parseRecord :: Record -> Parser a
@@ -109,12 +108,11 @@ newtype Only a = Only {
--
-- An example type and instance:
--
--- @data Person = Person { name :: Text, age :: Int }
---
--- instance ToRecord Person where
--- toRecord (Person name age) = 'record' [
--- 'toField' name, 'toField' age]
--- @
+-- > data Person = Person { name :: Text, age :: Int }
+-- >
+-- > instance ToRecord Person where
+-- > toRecord (Person name age) = 'record' [
+-- > 'toField' name, 'toField' age]
--
-- Outputs data on this form:
--
@@ -285,15 +283,14 @@ instance (ToField a, U.Unbox a) => ToRecord (U.Vector a) where
--
-- here's an example type and instance:
--
--- @{-\# LANGUAGE OverloadedStrings \#-}
---
--- data Person = Person { name :: Text, age :: Int }
---
--- instance FromRecord Person where
--- parseNamedRecord m = Person '<$>'
--- m '.:' \"name\" '<*>'
--- m '.:' \"age\"
--- @
+-- > {-# LANGUAGE OverloadedStrings #-}
+-- >
+-- > data Person = Person { name :: Text, age :: Int }
+-- >
+-- > instance FromRecord Person where
+-- > parseNamedRecord m = Person <$>
+-- > m .: "name" <*>
+-- > m .: "age"
--
-- Note the use of the @OverloadedStrings@ language extension which
-- enables 'B8.ByteString' values to be written as string literals.
@@ -309,12 +306,11 @@ class FromNamedRecord a where
--
-- An example type and instance:
--
--- @data Person = Person { name :: Text, age :: Int }
---
--- instance ToRecord Person where
--- toNamedRecord (Person name age) = 'namedRecord' [
--- \"name\" '.=' name, \"age\" '.=' age]
--- @
+-- > data Person = Person { name :: Text, age :: Int }
+-- >
+-- > instance ToRecord Person where
+-- > toNamedRecord (Person name age) = namedRecord [
+-- > "name" .= name, "age" .= age]
class ToNamedRecord a where
toNamedRecord :: a -> NamedRecord
@@ -349,17 +345,16 @@ instance ToField a => ToNamedRecord (HM.HashMap B.ByteString a) where
--
-- Example type and instance:
--
--- @{-\# LANGUAGE OverloadedStrings \#-}
---
--- data Color = Red | Green | Blue
---
--- instance FromField Color where
--- parseField s
--- | s == \"R\" = pure Red
--- | s == \"G\" = pure Green
--- | s == \"B\" = pure Blue
--- | otherwise = mzero
--- @
+-- > {-# LANGUAGE OverloadedStrings #-}
+-- >
+-- > data Color = Red | Green | Blue
+-- >
+-- > instance FromField Color where
+-- > parseField s
+-- > | s == "R" = pure Red
+-- > | s == "G" = pure Green
+-- > | s == "B" = pure Blue
+-- > | otherwise = mzero
class FromField a where
parseField :: Field -> Parser a
@@ -367,15 +362,14 @@ class FromField a where
--
-- Example type and instance:
--
--- @{-\# LANGUAGE OverloadedStrings \#-}
---
--- data Color = Red | Green | Blue
---
--- instance ToField Color where
--- toField Red = \"R\"
--- toField Green = \"G\"
--- toField Blue = \"B\"
--- @
+-- > {-# LANGUAGE OverloadedStrings #-}
+-- >
+-- > data Color = Red | Green | Blue
+-- >
+-- > instance ToField Color where
+-- > toField Red = "R"
+-- > toField Green = "G"
+-- > toField Blue = "B"
class ToField a where
toField :: a -> Field
Please sign in to comment.
Something went wrong with that request. Please try again.