Search code examples
haskellhaskelldb

HaskellDB - 'Database' variable is not in scope


I am trying to run this haskelldb hello world example,

module Caturday.Model.Connect where

import Database.HaskellDB.HDBC
import Database.HaskellDB.Sql.PostgreSQL
import Database.HDBC.PostgreSQL (connectPostgreSQL)

withDB :: [(String,String)] -> (Database -> IO a) -> IO a
withDB opts = hdbcConnect generator (connectPostgreSQL conninfo)
  where conninfo = unwords [ k ++ "=" ++ v | (k,v) <- opts ]

opts = [("host","localhost")
       ,("user","your_username")
       ,("password","your_password")
       ,("dbname","your_db_name")]

This code is taken from the site

On doing runhaskell db.hs, it throws error as,

db.hs:7:33: Not in scope: type constructor or class ‘Database’

And the line is,

withDB :: [(String,String)] -> (Database -> IO a) -> IO a

Solution

  • import Database.HaskellDB

    Database defined there, it should help

    ( https://github.com/m4dc4p/haskelldb/blob/master/src/Database/HaskellDB.hs#L68 )