#1571: type of synthesize in Data.Generics.Schemes is too restrictive
----------------------------------+-----------------------------------------
  Reporter:  [EMAIL PROTECTED]  |          Owner:                
      Type:  bug                  |         Status:  new           
  Priority:  normal               |      Milestone:                
 Component:  libraries/base       |        Version:  6.6.1         
  Severity:  normal               |       Keywords:  synthesize,syb
Difficulty:  Easy (1 hr)          |             Os:  Linux         
  Testcase:                       |   Architecture:  x86           
----------------------------------+-----------------------------------------
The type of the synthesize function in Data.Generics.Schemes is
 unnecessarily restrictive. It's current type is

 synthesize :: s  -> (s -> s -> s) -> GenericQ (s -> s) -> GenericQ s

 but it would be more useful if it were

 synthesize :: s -> (t -> s -> s) -> GenericQ (s -> t) -> GenericQ t

 Below is a contrived example demonstrating why one might want the more
 liberal type.

 module Main where

 import Data.Generics

 synthesize' :: s -> (t -> s -> s) -> GenericQ (s -> t) -> GenericQ t
 synthesize' z o f x = f x (foldr o z (gmapQ (synthesize' z o f) x))

 -- The toTree function fails to type if synthesize' is replaced
 -- with synthesize.

 data ConstructorTree = ConstructorTree String [ConstructorTree] deriving
 (Show)

 toTree :: Data a => a -> ConstructorTree
 toTree = synthesize' [] (:) (\a s -> ConstructorTree (showConstr (toConstr
 a)) s)

 data Foo = Bar String | Baz Foo Int deriving (Data,Typeable)

 main = print (toTree (Baz (Bar "12") 5))

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1571>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to