[Haskell] XML Serialization and type constraints
Simon D. Foster
u1sf at dcs.shef.ac.uk
Wed Aug 25 11:14:48 EDT 2004
On Wed, 2004-08-25 at 14:00, Tomasz Zielonka wrote:
> On Wed, Aug 25, 2004 at 01:54:08PM +0100, Simon D. Foster wrote:
> > On Wed, 2004-08-25 at 08:39, Tomasz Zielonka wrote:
> > - snip -
> > > I hope that helps,
> > >
> > > Best regards,
> > > Tom
> > That method works perfectly! Thank you so much! I assume there is no way
> > of achieving this without overlapping instances?
I think I jumped the gun it a bit; it almost works, but when I try to
declare a serializer for a type with several parts e.g.
data Person = Person PackedString PackedString Int
instance (Hook Person t) => Serializer Person t where ...
If I try to call encode on any of the attributes I get;
Could not deduce (Hook PackedString t)
from the context (Serializer Person t,
Hook Person t,
Hook Person t)
Thus, I have to add a (Hook x t) constraint for every type that is part
of the given data-type. For your example try;
data D = D Int
instance (Mixin D t) => Serializer D t where
encodePrim t (D n) = "(D " ++ encode t n ++ ")"
Is there anyway of getting around this?
Simon D. Foster <u1sf at dcs.shef.ac.uk>
More information about the Haskell