SQLite3 haskell createFunction 示例

发布于 2024-10-20 07:35:03 字数 962 浏览 6 评论 0原文

以下是能够创建函数的 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

Here's the SQLite3 Haskell bindings with the ability to create function: http://hackage.haskell.org/packages/archive/sqlite/0.5.1/doc/html/Database-SQLite.html

But I can't get to use this feature, I wrote the code like this:

increment a = a + 1

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

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

But it isn't compile with "Not in scope: data constructor `IsFunctionHandler'" error


The correct code is:

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)"

Thanks to HaskellElephant

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薆情海 2024-10-27 07:35:03

IsFunctionHandler 是一个类,而不是数据构造函数。它有几个实例< /a> 因此,如果 incrementIsFunctionHandler 的实例(在本例中就是这样),您应该能够编写:

createFunction handle "woot" increment

IsFunctionHandler is a class, not a data constructor. It has several instances so if increment is an instance of IsFunctionHandler, wich it in this case is, you should be able to write:

createFunction handle "woot" increment
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文