[Template-haskell] Instance declarations

Simon Peyton-Jones simonpj@microsoft.com
Wed, 19 Feb 2003 15:21:54 -0000


Can you give the actual source code for the offending program, please?

Simon

| -----Original Message-----
| From: Derek Elkins [mailto:ddarius86@hotmail.com]
| Sent: 13 February 2003 20:29
| To: template-haskell@haskell.org
| Subject: [Template-haskell] Instance declarations
|=20
| My first email seems to have gotten lost, if it meanders it's way
here, then
| sorry for the repeat.
|=20
| Anyways, generating a set of pattern matching functions in an instance
| declaration (maybe in general, though I haven't tested it) causes a
| "conflicting definitions error".  Rewriting as a case expression is
one
| work-around.
|=20
| E.g.
|=20
| instance (NFData a) =3D> NFData (Tree a) where
|     rnf (Leaf a) =3D rnf a
|     rnf (Branch a b) =3D rnf a `seq` rnf b
|=20
| doesn't work, but rewriting as
|=20
| instance (NFData a) =3D> NFData (Tree a) where
|     rnf x =3D case x of
|               (Leaf a) -> rnf a
|               (Branch a b) -> rnf a `seq` rnf b
|=20
| does.
|=20
| I suspect that it may have to do with the generated code being
considered at
| a lower level (i.e. the transformation of the above into the below is
| already considered done).  It may just be I'm creating the functions
| incorrectly, so if you can't get the error to happen I can provide the
code
| I'm using.
|=20
| Separately: I've written a variety of fold algebras over data
declarations.
| I'm not sure how useful they'll be, but if you're interested email me,
and
| I'll email the source.  I haven't tested them, but it's pretty
mechanical
| code so I don't suspect any major problems and any should be
relatively
| straightforward to fix.  See `Dealing with Large Bananas` for the
concept
| (and for documentation, as it has no documentation yet).
|=20
| _________________________________________________________________
| STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
| http://join.msn.com/?page=3Dfeatures/junkmail
|=20
| _______________________________________________
| template-haskell mailing list
| template-haskell@haskell.org
| http://www.haskell.org/mailman/listinfo/template-haskell