関数を作成する機能を備えた SQLite3 Haskell バインディングは次のとおりです。
しかし、私はこの機能を使用することができません。私は次のようなコードを書きました:
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 に感謝