-
Simon Peyton Jones authored
--------------------------------------------- More type system extensions (for John Hughes) --------------------------------------------- 1. Added a brand-new extension that lets you derive ARBITRARY CLASSES for newtypes. Thus newtype Age = Age Int deriving( Eq, Ord, Shape, Ix ) The idea is that the dictionary for the user-defined class Shape Age is *identical* to that for Shape Int, so there is really no deriving work to do. This saves you writing the very tiresome instance decl: instance Shape Age where shape_op1 (Age x) = shape_op1 x shape_op2 (Age x1) (Age x2) = shape_op2 x1 x2 ...etc... It's more efficient, too, becuase the Shape Age dictionary really will be identical to the Shape Int dictionary. There's an exception for Read and Show, because the derived instance *isn't* the same. There is a complication where higher order stuff is involved. Here is the example John gave: class StateMonad s m | m -> s where ... newtype Pa...
91c750cb