258 | | '''MS note''': How to fix the (modularity) problem via indexed classes? |

| 257 | We fix the problem by by introducing an indexed class |

| 258 | in gmapQ's context. Thus, we can 'enable' the 'Size' class |

| 259 | when needed. |

| 260 | |

| 261 | {{{ |

| 262 | -- type family |

| 263 | class family Context ctxt :: * -> class |

| 264 | |

| 265 | class Typeable t => Data ctxt t where |

| 266 | gmapQ :: (forall e . Data e ctxt, Context ctxt e => e -> r) -> t -> [r] |

| 267 | |

| 268 | instance Data Char ctxt where |

| 269 | gmapQ f c = [] |

| 270 | |

| 271 | instance Data e ctxt => Data [e] ctxt where |

| 272 | gmapQ f (x:xs) = [f x,f xs] |

| 273 | |

| 274 | |

| 275 | class Size t where |

| 276 | gsize :: t -> Int |

| 277 | |

| 278 | instance Size t where |

| 279 | gsize = 42 |

| 280 | |

| 281 | ... |

| 282 | |

| 283 | instance Data t SizeCtxt => Size t where |

| 284 | gsize x = 1 + sum (gmapQ gsize x) |

| 285 | |

| 286 | data SizeCtxt -- uninhabited |

| 287 | |

| 288 | class instance Context SizeCtxt e = Size e |

| 289 | }}} |