type classes and generality

Norman Ramsey nr@eecs.harvard.edu
Mon, 09 Jul 2001 18:26:27 -0400

 > On 09-Jul-2001, Norman Ramsey <nr@eecs.harvard.edu> wrote:
 > > I'm trying to model probability and leave the
 > > representation of probability unspecified other than
 > > it must be class Real.  But I'm having trouble with
 > > random numbers; how can I show that if a type has class Real,
 > > it also has class Random.Random?  Is there a way to accomplish
 > > this goal other than by changing the library?
 > I'm not sure if I fully understand your goal.
 > But one thing you can do is to define a wrapper type
 > 	newtype WrapReal r = WrapReal r
 > and make the wrapper an instance of Random.Random
 > if the underlying type is an instance of Real
 > 	instance Real r => Random.Random (WrapReal r) where
 > 		...
 > Then you can use the wrapper type whenever you want to get a random number.

The problem is that without intensional type analysis, I wouldn't know
how to fill in the instance methods in the `...'