2

这是具有创建功能的 SQLite3 Haskell 绑定:http: //hackage.haskell.org/packages/archive/sqlite/0.5.1/doc/html/Database-SQLite.html

但是我不能使用这个功能,我写了这样的代码:

increment a = a + 1

checkout = do
       handle <- openConnection "test.db"
       ok <- createFunction handle "woot" (IsFunctionHandler increment)

       return $ execStatement handle "SELECT woot(5)";

但它没有编译“不在范围内:数据构造函数‘IsFunctionHandler’”错误


正确的代码是:

module Test where

import Database.SQLite
import Int

increment :: Int64 -> Int64
increment a = a + 1

checkout :: IO (Either String [[Row Value]])
checkout = do
       handle <- openConnection "test.db"
       ok <- createFunction handle "woot" increment

       execStatement handle "SELECT woot(5), woot(7), woot(128)"

感谢 HaskellElephant

4

1 回答 1

2

IsFunctionHandler是一个类,而不是数据构造函数。它有几个实例,所以如果increment是 的一个实例IsFunctionHandler,在这种情况下它是,你应该能够写:

createFunction handle "woot" increment
于 2011-03-04T13:19:22.627 回答