示例postgresql-simple-migration程序无法编译

时间:2017-12-21 05:56:15

标签: haskell

我正在尝试开始使用postgresql-simple-migration库,但是在编译列出的示例程序时遇到了问题。

示例程序(如下所示)是postgresql-simple-migration hackage page上列出的“初始化数据库”示例。

main :: IO ()
main = do
    let url = "host=$host dbname=$db user=$user password=$pw"
    con <- connectPostgreSQL (BS8.pack url)
    withTransaction con $ runMigration $
        MigrationContext MigrationInitialization True con

似乎我需要做的就是编译导入正确的模块。导入包含这些术语的postgresql-simple-migration模块以及Data.ByteString.Char8使pack具有预期类型的​​模块,将提供以下内容。

import Database.PostgreSQL.Simple.Migration
import Database.PostgreSQL.Simple
import Data.ByteString.Char8 as BS8

main :: IO ()
main = do
    let url = "host=$host dbname=$db user=$user password=$pw"
    con <- connectPostgreSQL (BS8.pack url)
    withTransaction con $ runMigration $
        MigrationContext MigrationInitialization True con

但是,尝试编译会导致类型错误。

$ stack build
Building all executables for `db' once. After a successful build of all of them, only specified executables will be rebuilt.
db-0.1.0.0: build (lib + exe)
Preprocessing library db-0.1.0.0...
Preprocessing executable 'db-exe' for db-0.1.0.0...
[1 of 1] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0/build/db-exe/db-exe-tmp/Main.o )

/home/matthew/backup/organizeactions/taskmasterplatform/db/app/Main.hs:12:5: error:
    • Couldn't match type ‘MigrationResult String’ with ‘()’
      Expected type: IO ()
        Actual type: IO (MigrationResult String)
    • In a stmt of a 'do' block:
        withTransaction con
        $ runMigration $ MigrationContext MigrationInitialization True con
      In the expression:
        do { let url = "host=$host dbname=$db user=$user password=$pw";
             con <- connectPostgreSQL (pack url);
             withTransaction con
             $ runMigration
               $ MigrationContext MigrationInitialization True con }
      In an equation for ‘main’:
          main
            = do { let url = ...;
                   con <- connectPostgreSQL (pack url);
                   withTransaction con
                   $ runMigration
                     $ MigrationContext MigrationInitialization True con }

--  While building custom Setup.hs for package db-0.1.0.0 using:
      /home/matthew/.stack/setup-exe-cache/x86_64-linux-nix/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0 build lib:db exe:db-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

runMigrationDatabase.PostgreSQL.Simple.Migration)的类型为

`runMigration :: MigrationContext -> IO (MigrationResult String)`

(MigrationResult String)()的类型签名中标记的main不符。

为什么示例不编译?

  • 我是否需要从其他模块导入?
  • 示例是否包含错误?

0 个答案:

没有答案