Changes between Version 11 and Version 12 of TypeFunctions/ClassFamilies
 Timestamp:
 May 29, 2007 2:45:41 AM (9 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

TypeFunctions/ClassFamilies
v11 v12 247 247 forall a. Size a => a > Int 248 248 }}} 249 But the second type is not a subtype of the second. 249 But the second type is not a subtype of the second 250 because we cannot derive 'Size a' from 'Data a' for any 'a'. 250 251 For this subtype relation to hold, if we can satisfy 251 the condition252 that from 'Data a' we can derive 'Size a' for any 'a'.253 252 This condition is satisfied 254 253 if we make 'Sizes' a superclass of 'Data'. … … 256 255 'Data's class declaration for each new generic function). 257 256 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 }}} 259 290 260 291 === Type checking ===