[Haskell-cafe] coding standard question

Daniel Fischer daniel.is.fischer at web.de
Mon Jun 29 09:41:19 EDT 2009


Am Montag 29 Juni 2009 10:47:05 schrieb david48:
> Hello Daniel and all,
> Your suggestion #1 : Can't import Database.HDBC.MySQL.Connection :
>
> david at pcdavid2:~/projets/haskell/caimonitor$ ghci -Wall Bdd.hs
> GHCi, version 6.10.3: http://www.haskell.org/ghc/  :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer ... linking ... done.
> Loading package base ... linking ... done.
>
> Bdd.hs:15:7:
>    Could not find module `Database.HDBC.MySQL.Connection':
>      it is a hidden module in the package `HDBC-mysql-0.6'
>      Use -v to see a list of the files searched for.
> Failed, modules loaded: none.
> Prelude>
> Leaving GHCi.

That wouldn't help, actually, it doesn't export the type either, as the sources revealed.

>
> Your suggestion #2 : Unfortunately, the type isn't exported, as it seems :
>
> The doc says :
>
> *This module provides a MySQL driver for the HDBC database interface.
> To use it, invoke the 'connectMySQL' method to create an
> @Database.HDBC.IConnection@ that you can use to interact with a MySQL
> database.  Use the 'defaultMySQLConnectInfo', overriding the default
> values as necessary.*
>
> so I tried :
> connecter :: IO IConnection
> connecter = connectMySQL mysqlInfo
>
> But then that didn't work too, because IConnection is a class, not a type (
> which is not obvious from the documentation snippet I read)
>
> So then I tried :
>
> connecter :: IConnection conn => conn
> connecter = connectMySQL mysqlInfo
>
> And even though I suspect that's the correct type, it fails too :

No, that's too general a type, that says "whatever inctsnce of IConnection you desire, I 
can deliver it", but connecter can deliver only one type (and there's an IO missing).

Since the type is not exported, you can't use it in type signatures.
You have two options:
a) omit the type signature :(
b) wrap it in a ConnWrapper:

connecter :: IO ConnWrapper
connecter = ConnWrapper `fmap` connectMySQL mysqlInfo

and use it via withWConn

c) maybe there's another option I didn't see


> I looked at Connection.hsc from the library and the Connection type defined
> there isn't exported.
>
> For now, I've disabled that type of warnings.
>
> Thanks,
>
> David.



More information about the Haskell-Cafe mailing list