SQLite3 haskell createFunction 示例
以下是能够创建函数的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IsFunctionHandler
是一个类,而不是数据构造函数。它有几个实例< /a> 因此,如果increment
是IsFunctionHandler
的实例(在本例中就是这样),您应该能够编写:IsFunctionHandler
is a class, not a data constructor. It has several instances so ifincrement
is an instance ofIsFunctionHandler
, wich it in this case is, you should be able to write: