1

I was trying to convert a SqlValue into UTCTime like this:

import Database.HDBC
import Data.Time (UTCTime)

getUTCTimeFromSql :: SqlValue -> UTCTime
getUTCTimeFromSql time = fromSql time :: UTCTime

But GHC complains that I'm missing a Convertible instance to do this:

No instance for (Data.Convertible.Base.Convertible
                   SqlValue UTCTime)
  arising from a use of `fromSql'
Possible fix:
  add an instance declaration for
  (Data.Convertible.Base.Convertible SqlValue UTCTime)
In the expression: fromSql time :: UTCTime
In an equation for `getUTCTimeFromSql':
    getUTCTimeFromSql time = fromSql time :: UTCTime

When I look at the HDBC source code, the instance for UTCTime is there.

Am I missing something?

Daisuke Shimamoto
  • 5,206
  • 6
  • 32
  • 37
  • 2
    I could successfully load the snippet to GHCi (7.4.2) with HDBC-2.3.1.2 and convertible-1.0.11.1. What versions do you use? – snak Mar 12 '13 at 05:43
  • 3
    I suspect that your `HDBC` (and `convertible`) were built against a different version of `time` than you are using. So there's an instance for the `UTCTime` of the older `time` package, but not for the type from the newer. Does `ghc-pkg list time` report more than one installed version? – Daniel Fischer Mar 12 '13 at 12:17
  • Daniel, yes, indeed that was the reason. I had two versions of time registered so I removed one, re-installed some packages and it worked! – Daisuke Shimamoto Mar 12 '13 at 22:35

1 Answers1

0

Please refer to Daniel's comment for the answer.

I suspect that your HDBC (and convertible) were built against a different version of time than you are using. So there's an instance for the UTCTime of the older time package, but not for the type from the newer. Does ghc-pkg list time report more than one installed version?

Community
  • 1
  • 1
Daisuke Shimamoto
  • 5,206
  • 6
  • 32
  • 37