# type classes and generality

**Fergus Henderson
**
fjh@cs.mu.oz.au

*Tue, 10 Jul 2001 08:17:31 +1000*

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.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.