Robert Ennals <Robert.Ennals@cl.cam.ac.uk> writes: [Heavy snippage, hopefully preserving semantics]
data Foo = Foo {wibble :: Int, wobble :: String} deriving Wibble
We could imagine the definition of Foo being automatically desugared to the following:
data Foo = Foo Int String
instance Wibble Foo where wibble (x,_) = x wobbble (_,y) = y set_wibble x (_,y) = (x,y) set_wobble y (x,_) = (x,y)
Shouldn't that rather be: class HasWibble a where wibble :: a -> Int set_wibble :: a -> Int -> a class HasWobble a where ... data Foo = Foo Int String instance HasWibble Foo where wibble (Foo x _) = x set_wibble (Foo x y) z = Foo z y instance HasWobble Fo where... In order to let another record provide just a 'wibble' without a 'wobble'? One danger of such an approach (implicit classes and instances) might be non-intuitive error messages. -kzm -- If I haven't seen further, it is by standing in the footprints of giants