
Andy Stewart wrote:
So have a better solution to avoid write above ugly code How about:
==== data Page a = Page {pageName :: IORef String ,pageId :: Int ,pageBuffer :: a ,pageBox :: VBox } class PageBuffer a where pageBufferClone :: a -> IO (a, VBox) pageClone :: PageBuffer a => Page a -> IO (Page a) pageClone page = do -- Get common information for clone page. name <- pageGetName page let id = pageId page pb = pageBuffer page -- Get clone information for dynamic interface. (pBuffer, pBox) <- pageBufferClone pb -- Return clone page. pageNewInternal name id pBuffer pBox ==== I'm not totally sure if that will work without seeing the rest of your code. But it seems neater, and no GADTs in sight. If you need to store Page StringBuffer in a list with Page ImageBuffer you will have a problem, so perhaps you could spell out what else you need to do with these Page items in your application? Thanks, Neil.