@@ -697,10 +697,11 @@ fmtError msg q xs = throw FormatError {
697697-- >
698698-- > import Database.PostgreSQL.Simple
699699-- >
700−-- > hello :: IO [Only Int]
700+-- > hello :: IO Int
701701-- > hello = do
702702-- > conn <- connectPostgreSQL ""
703−-- > query_ conn "select 2 + 2"
703+-- > [Only i] <- query_ conn "select 2 + 2"
704+-- > return i
704705--
705706-- A 'Query' value does not represent the actual query that will be
706707-- executed, but is a template for constructing the final query.
@@ -761,11 +762,26 @@ fmtError msg q xs = throw FormatError {
761762-- The same kind of problem can arise with string literals if you have
762763-- the @OverloadedStrings@ language extension enabled. Again, just
763764-- use an explicit type signature if this happens.
765+--
766+-- Finally, remember that the compiler must be able to infer the type
767+-- of a query's /results/ as well as its parameters. We might like
768+-- the following example to work:
769+--
770+-- > print =<< query_ conn "select 2 + 2"
771+--
772+-- Unfortunately, while a quick glance tells us that the result type
773+-- should be a single row containing a single numeric column, the
774+-- compiler has no way to infer what the types are. We can easily fix
775+-- this by providing an explicit type annotation:
776+--
777+-- > xs <- query_ conn "select 2 + 2"
778+-- > print (xs :: [Only Int])
764779
765780-- $only_param
766781--
767782-- Haskell lacks a single-element tuple type, so if you have just one
768−-- value you want substituted into a query, what should you do?
783+-- value you want substituted into a query or a single-column result,
784+-- what should you do?
769785--
770786-- The obvious approach would appear to be something like this:
771787--
@@ -780,6 +796,9 @@ fmtError msg q xs = throw FormatError {
780796--
781797-- > execute conn "insert into users (first_name) values (?)"
782798-- > ["Nuala"]
799+--
800+-- A row of /n/ query results is represented using an /n/-tuple, so
801+-- you should use 'Only' to represent a single-column result.
783802
784803-- $in
785804--