2009年7月28日火曜日

Haskellはじめました -その2-

HDBC-sqlite3のインストールはできたみたいだけど、GHCiの実行時にモジュールが読み込めずにエラーになる。ん~、なんか足りないんだろうな。

GOOGLE先生に聞いたところ、以下のページにたどりついた。
http://software.complete.org/software/wiki/13/FrequentlyAskedQuestions

ようするに
①SQLiteのサイトから"sqlite-source-${current version}.zip"をダウンロードする。
②解凍して"$GHC_HOME/include/"にコピーする。
③同様に"sqlitedll-${current version}.zip"をダウンロードする。
④解凍して"$GHC_HOME"と"%windir%\system32"にコピーする。
※「$GHC_HOME」は、コマンドラインで「ghc --print-libdir」で表示できる。



GHCi, version 6.10.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> :module Database.HDBC Database.HDBC.Sqlite3
Prelude Database.HDBC Database.HDBC.Sqlite3> conn <- connectSqlite3 "C:\\Users\\
Public\\Documents\\test.db"
Loading package syb ... linking ... done.
Loading package array-0.2.0.0 ... linking ... done.
Loading package containers-0.2.0.1 ... linking ... done.
Loading package bytestring-0.9.1.4 ... linking ... done.
Loading package old-locale-1.0.0.1 ... linking ... done.
Loading package old-time-1.0.0.2 ... linking ... done.
Loading package Win32-2.2.0.0 ... linking ... done.
Loading package mtl-1.1.0.2 ... linking ... done.
Loading package time-1.1.4 ... linking ... done.
Loading package convertible-1.0.5 ... linking ... done.
Loading package utf8-string-0.3.5 ... linking ... done.
Loading package HUnit-1.2.0.3 ... linking ... done.
Loading package base-3.0.3.1 ... linking ... done.
Loading package random-1.0.0.1 ... linking ... done.
Loading package QuickCheck-1.2.0.0 ... linking ... done.
Loading package filepath-1.1.0.2 ... linking ... done.
Loading package directory-1.0.0.3 ... linking ... done.
Loading package process-1.0.1.1 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package testpack-1.0.2 ... linking ... done.
Loading package HDBC-2.1.1 ... linking ... done.
Loading package HDBC-sqlite3-2.1.0.2 ... linking ... done.
Prelude Database.HDBC Database.HDBC.Sqlite3> :type conn
conn :: Connection
Prelude Database.HDBC Database.HDBC.Sqlite3>



つながった!

2009年7月26日日曜日

Haskellはじめました -その2-

Cabalの基本的な使い方が解ったので、Haskellでデータベース接続をするべくHDBCのインストールに挑戦。
DBはお手軽なSQLiteで試したい。



C:\Users\Dog\Downloads\Hackage\HDBC-sqlite3-2.1.0.2>runghc setup configure
Configuring HDBC-sqlite3-2.1.0.2...
setup: Missing dependency on a foreign library:
* Missing C library: sqlite3
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.



あらら早速エラーです。
なにやら依存するファイルが足りないとか。「--extra-include-dirs」とか「--extra-include-dirs」オプションを指定しろって?
SQLiteのサイトからsourceとDLLを拾ってくる。それらを解凍し、「--extra-include-dirs」と「--extra-include-dirs」にフォルダを指定してみる。



C:\Users\Dog\Downloads\Hackage\HDBC-sqlite3-2.1.0.2>runghc setup configure -
-extra-lib-dirs=C:\Users\suzuken\Downloads\sqlitedll-3_6_16 --extra-include-dirs
=C:\Users\suzuken\Downloads\sqlite-amalgamation-3_6_16
Configuring HDBC-sqlite3-2.1.0.2...



あ、今度は通った。
installまで実行して、GHCiで



Prelude> :module Database.HDBC Database.HDBC.Sqlite3
Prelude Database.HDBC Database.HDBC.Sqlite3> conn <- connectSqlite3 "test"



あれ?エラーになるぞ?
まだなにか足りないらしい。。。

2009年7月23日木曜日

Haskellはじめました

HaskellがやりたくてWindowsVistaにGHCをインストールしたのだが、普段上業務用アプリケーションの開発に携わっているため、データベースを使いたくなってくる。
GHCにはデータベース関連のモジュールは入っていないらしい。というか、どうやって入れるんだ?

HaskellにはCabalというパッケージシステムがあるらしい。

パッケージはHackageDBというサイトで公開されている。

Cabalパッケージを手動インストールするには、ダウンロードしたファイルを解凍し、以下のコマンドを実行する。

runghc Setup.hs configure
runghc Setup.hs build
runghc Setup.hs install

具体的には以下のような感じ。



Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\Users\suzuken>cd C:\Users\dog\Downloads\Hackage\HDBC-2.1.1

C:\Users\dog\Downloads\Hackage\HDBC-2.1.1>dir
ドライブ C のボリューム ラベルは OS です
ボリューム シリアル番号は 00XX-0X0X です

C:\Users\suzuken\Downloads\Hackage\HDBC-2.1.1 のディレクトリ

2009/07/23 22:01 <DIR> .
2009/07/23 22:01 <DIR> ..
2009/05/30 05:15 26,527 COPYING
2009/05/30 05:15 844 COPYRIGHT
2009/07/23 22:01 <DIR> Database
2009/05/30 05:15 2,060 HDBC.cabal
2009/05/30 05:15 79 Setup.lhs
2009/07/23 22:01 <DIR> testsrc
4 個のファイル 29,510 バイト
4 個のディレクトリ 11,231,596,544 バイトの空き領域

C:\Users\suzuken\Downloads\Hackage\HDBC-2.1.1>runghc Setup.lhs configure
Configuring HDBC-2.1.1...
Setup.lhs: At least the following dependencies are missing:
convertible >=1.0.1,
testpack -any,
time >=1.1.2.4,
utf8-string -any

C:\Users\suzuken\Downloads\Hackage\HDBC-2.1.1>


runghc Setup.lhs configureの後、パッケージの依存関係がチェックされ、必要なパッケージとそのバージョンが表示されるので、それらをインストールしてから、再度インストールする。