Question

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?

Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top