[Haskell-cafe] SYB with class: Bug in Derive.hs module

Alexey Rodriguez Yakushev mrchebas at gmail.com
Mon Mar 31 09:47:04 EDT 2008

Hi people (and Ralf and Alex),

I found a bug in the SYB with class library when trying to implement  
generic equality. I am hoping that someone in the Cafe (maybe Ralf)  
can confirm it is a bug, or maybe show me that I am doing something  

I am using the "Scrap your boilerplate with class" library (http:// 
homepages.cwi.nl/~ralf/syb3/). More precisely, I am using the library  
distributed by the HAppS project, because it works with GHC 6.8 . You  
can get the repository as follows:

darcs get http://happs.org/HAppS/syb-with-class

However, the offending module (Derive.hs) produces broken instances  
in both distributions.

The bug:

Generic equality needs type safe casting when implemented in SYB3, I  
have tried both the gzipwith variant and using Pack datatypes  
(geq*.hs in the first distribution). However, both functions loop  
when applied to a tree value.

This loop occurs when the functions try to cast one of the arguments.  
I have managed to reduce the error to a smaller source file that I  
send attached. It does the following:

 > main = print typeReps
 > tree = (Bin (Leaf 1) (Leaf 2))::BinTree Int
 > data Pack = forall x. Typeable x => Pack x
 > packedChildren = gmapQ geqCtx Pack tree
 > typeOfPack (Pack x) = typeOf x
 > typeReps = map typeOfPack packedChildren

Basically the tree is transformed into a list of Pack-ed values and  
then to a list of type representations. This program loops at  
"typeOf" when you call "main".

The Data instance that Derive generates is as follows:

 > instance (Data ctx a,
 >                   Data ctx (BinTree a),
 >                   Sat (ctx (BinTree a))) =>
 >                   Data ctx (BinTree a) where

Note the recursive |Data ctx (BinTree a)| in the context. If I get  
rid of it (a correct manual instance is also included in the  
attachment) the example works.

I thought of removing this from the context in the Derive source. But  
maybe I might break some other use cases. So I am asking for help!  
Should Derive be fixed? How?



-------------- next part --------------
A non-text attachment was scrubbed...
Name: BugBinTree.lhs
Type: application/octet-stream
Size: 3490 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080331/ff9d2d8f/BugBinTree.obj

More information about the Haskell-Cafe mailing list