Haskell SQLite-Simple type error

Viewed 267

I am trying to run an example using sqlite-simple from this Hackage page:

{-# LANGUAGE OverloadedStrings #-}

module Main where
import Database.SQLite.Simple

main :: IO ()
main = do
  conn <- open "test.db"
  [[x]] <- query_ conn "select 2 + 2"
  print x

But I get this error:

Prelude> :load sqltest.hs
[1 of 1] Compiling Main             ( sqltest.hs, interpreted )

sqltest.hs:9:12: error:
    • Ambiguous type variable ‘a0’ arising from a use of ‘query_’
      prevents the constraint ‘(Database.SQLite.Simple.FromField.FromField
                                  a0)’ from being solved.
      Probable fix: use a type annotation to specify what ‘a0’ should be.
      These potential instances exist:
        instance Database.SQLite.Simple.FromField.FromField Integer
          -- Defined in ‘Database.SQLite.Simple.FromField’
        instance Database.SQLite.Simple.FromField.FromField a =>
                 Database.SQLite.Simple.FromField.FromField (Maybe a)
          -- Defined in ‘Database.SQLite.Simple.FromField’
        instance Database.SQLite.Simple.FromField.FromField Bool
          -- Defined in ‘Database.SQLite.Simple.FromField’
        ...plus five others
        ...plus 15 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In a stmt of a 'do' block: [[x]] <- query_ conn "select 2 + 2"
      In the expression:
        do { conn <- open "test.db";
             [[x]] <- query_ conn "select 2 + 2";
             print x }
      In an equation for ‘main’:
          main
            = do { conn <- open "test.db";
                   [[x]] <- query_ conn "select 2 + 2";
                   print x }

sqltest.hs:10:3: error:
    • Ambiguous type variable ‘a0’ arising from a use of ‘print’
      prevents the constraint ‘(Show a0)’ from being solved.
      Relevant bindings include x :: a0 (bound at sqltest.hs:9:5)
      Probable fix: use a type annotation to specify what ‘a0’ should be.
      These potential instances exist:
        instance Show Ordering -- Defined in ‘GHC.Show’
        instance Show Integer -- Defined in ‘GHC.Show’
        instance Show FormatError -- Defined in ‘Database.SQLite.Simple’
        ...plus 28 others
        ...plus 35 instances involving out-of-scope types
        (use -fprint-potential-instances to see them all)
    • In a stmt of a 'do' block: print x
      In the expression:
        do { conn <- open "test.db";
             [[x]] <- query_ conn "select 2 + 2";
             print x }
      In an equation for ‘main’:
          main
            = do { conn <- open "test.db";
                   [[x]] <- query_ conn "select 2 + 2";
                   print x }
Failed, modules loaded: none. 

I installed sqlite-simple using Cabal. Then I tried to load the example code into GHCI. I am new to Haskell and am just trying simple examples.

1 Answers
Related