[Haskell-cafe] Opaque types vs automated instance deriving
Antoine Latter
aslatter at gmail.com
Tue Jun 21 04:17:59 CEST 2011
On Mon, Jun 20, 2011 at 5:07 PM, Alexey Karakulov <ankarakulov at gmail.com> wrote:
> Hi all,
> I encountered a problem when trying to
>
>> derive makeBinary ''DiffTime
>
> with help of derive package. The error was:
>
> Not in scope: data constructor `MkDiffTime'
>
> Which makes a sense, since it's not exported in Data.Time.Clock.
> I bypassed the problem (yes, I'm too lazy to write instances by hands) with
>
>> instance Binary UTCTime where
>> put =
>> putGeneric
>> get =
>> getGeneric
>
> But it must be less efficient (and more verbose) than compile-time deriving.
> If there was such a module like Data.Time.Clock.Internal, I could import it
> to get hidden constructors (and maybe I'll have to fork the library for this
> purpose).
>
> OTOH, is it possible to change the derive TH function so it can bypass
> module encapsulation mechanism and access un-exported things?
>
I would benchmark putGeneric/getGeneric against:
> put = put . toRational
> get = fromRational <$> get
It looks like that's what the safecopy package on Hackage uses.
Antoine
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
More information about the Haskell-Cafe
mailing list