Created
January 12, 2014 18:44
-
-
Save cosmo0920/8388646 to your computer and use it in GitHub Desktop.
hsc2hsで生成したバインディングを使うと全然関数型らしくないものができてしまった(途中)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Bindings.Groonga | |
import Foreign.C.String | |
import Foreign.C.Types() | |
import Foreign.Ptr | |
import Foreign.Storable() | |
import System.Directory | |
main :: IO () | |
main = do | |
-- init context | |
rc <- c'grn_init | |
ctx <- c'grn_ctx_open rc | |
-- comand version | |
com <- c'grn_ctx_get_command_version ctx | |
putStrLn $ show com | |
-- encoding | |
enc <- c'grn_get_default_encoding | |
cenc_str <- c'grn_encoding_to_string enc | |
enc_str <- peekCString cenc_str | |
putStrLn enc_str | |
-- show Groonga version | |
showVersion | |
let dbpath = "db/test.db" | |
file <- doesFileExist dbpath | |
if file then do | |
-- db open | |
dbname <- newCAString dbpath | |
db <- c'grn_db_open ctx dbname | |
showErrbuf ctx | |
putStrLn $ show db | |
else do | |
-- db create | |
dbname <- newCAString dbpath | |
db <- c'grn_db_create ctx dbname nullPtr | |
showErrbuf ctx | |
putStrLn $ show db | |
showErrbuf :: Ptr C'_grn_ctx -> IO () | |
showErrbuf ctx = do | |
let char = p'_grn_ctx'errbuf ctx | |
clog <- peekCString char | |
putStrLn clog | |
showVersion :: IO () | |
showVersion = do | |
version <- c'grn_get_version | |
ver <- peekCString version | |
putStrLn ver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment