[Haskell-cafe] Re: suggestions for doing date/time values with Data.Generics ?

Thomas Hartman tphyahoo at gmail.com
Mon Oct 5 15:54:33 EDT 2009


fwiw, this s what I'm doing till I figure out a better way:

import System.Time
data MyTime = MyTime Integer Integer
  deriving (Typeable,Data)
myTimeToClockTime (MyTime a b) = TOD a b
myTimeFromClockTime (TOD a b) = MyTime a b

and use MyTime in the happstack state.

2009/10/5 Thomas Hartman <tphyahoo at gmail.com>:
> I want to patch the time package, which I darcs got head on. Goal is
> to be able to do newtype deriving for UTCTime which I reckon is the
> base time value, for use in happstack applications state.
>
>
> basically, need instances for UTCTime, for Data and Typeable.
>
> **********
> on #haskell:
>
> <patch-tag> I just darcs got time package and attempted to install.
> cabal
>           install didn't work because missing configure fle. there's
> a .ac
>           file there, so I tried first autoconf, then cabal
>           install. configure file got created, but failed with
>           config.status: error: cannot find input file:
>           include/HsTimeConfig.h.in. now what?
> <patch-tag> my goal is to patch time package so can do data generics deriving.
>
> <Berengal> patch-tag, use System.Time instead?
> * Berengal shrugs and sighs                                             [12:20]
> <patch-tag> could try that...
> *** o-regalia (n=o-regali at host-0-130.mimpvbg.clients.pavlovmedia.com)
> has
>   quit: "Lost terminal"
> <Berengal> It already has a Serializeable instance defined in one of
> the
>          happstack modules, so there's probably a Typeable and Data
> instance
>          somewhere as well
>
>
>
> <Berengal> patch-tag, unfortunately, UTCTime has a component of a
> hidden
>          datatype which isn't an instance of Typeable or Data, and
> since
>          it's not exported it's impossible to create the instance as well
> <Berengal> If it were exported, it'd be pretty easy
> <patch-tag> hw can I use UTCTime, deriving Typeable and Data? (want to
> use
>           UTCTime in happstack).
> <patch-tag> http://moonpatio.com/fastcgi/hpaste.fcgi/view?id=4278#a4278
> <patch-tag> I guess I should have said I'd like to use newtype
> deriving rather
>           than define instance myself if that's possible.
>
>
> <Berengal> patch-tag, that's possible, but could break other things.
> The
>          correct solution is to patch the existing package, but that
> takes
>          time
> <Berengal> patch-tag, Day, or something. Can't remember off the top of my head
> *** paolino (n=paolino at 87.7.161.162) has quit: "Leaving."
> <ski> Philonous : if you can't implement both operations (satisfying
> laws),
>     though, it is probably better to make a new class                 [12:09]
> <patch-tag> Berengal: a package is hidden if when you do :info in
> ghci, it
>           comes out as fully qualified, right?
> <patch-tag> pity also that newtype deriving doesn't give you a nicer
> error
>           message like "deriving choked at type blah"
> <Berengal> patch-tag, it comes fully qualified if it's not imported,
> so you'll
>          have to try to import it to see if it's really hidden        [12:10]
>
>
> *********
>
> Seems like the right thing to do is patch the time package anyway.
>
>
> File Edit Options Buffers Tools Haskell Help
> {-# LANGUAGE DeriveDataTypeable #-}
> module TypeableTime where
>
> import Data.Time
> import Data.Data
> import Data.Generics
> import Data.Typeable
>
> -- doesn't work
> --data MyUTCTime = MyUTCTime UTCTime
> --   deriving (Typeable,Data)
>
> -- should I work up to UTCTime by doing this...?
> data MyDay = MyDay {toMyDayModifiedJulianDay :: Integer}
>  deriving (Typeable,Data)
>
> newtype MyString = MyString String
>  deriving (Read,Show,Ord,Eq,Typeable,Data)
>
> -- should I just modify time package? is this easier?
>


More information about the Haskell-Cafe mailing list