tags:

views:

85

answers:

2

I have data defined like the ff.:

import Data.Time.Clock

data D = D { ...,
             someDate :: UTCTime,
             ... }
         deriving (Eq, Show)

When I compile it, I get the ff. error:

No instance for (Show UTCTime)
  arising from the 'deriving' clause of a data type declaration
               at ...

I already have the time-1.1.3 package which should already have this instance according to documentation. My GHC version is 6.8.2.

+2  A: 

The documentation lies. If you look at the source for Data.Time.Clock.UTC, there simply is no Show instance for UTCTime.

Edit:

As newacct helpfully pointed out, there's an orphaned instance for Show UTCTime in Data.Time.LocalTime.LocalTime, so if you import that, your code will work.

sepp2k
it's in Data.Time.LocalTime.LocalTime though: http://hackage.haskell.org/packages/archive/time/1.1.3/doc/html/src/Data-Time-LocalTime-LocalTime.html
newacct
I emailed the package maintainer to clarify. I'll post here as soon as I get a reply.
Chry Cheng
It's an orphan instance defined in Data.Time.LocalTime.LocalTime. Importing Data.Time will give the constructor in Data.Time.UTC and the Show instance in Data.Time.LocalTime.LocalTime.
Chry Cheng
+5  A: 

Don't import each piece of the Data.Time suite separately. It's designed for you to import just Data.Time, and that will pull in just about everything that is commonly used. Including the Show instance for UTCTime.

If you don't want that much namespace clutter, import just the symbols you need:

import Data.Time (UTCTime, getCurrentTime)

or whatever else. That's anyway a good idea - it protects you against name clashes later on if the library gets updated and starts using a name that you have already defined.

Yitz