type classes and generality
Tue, 10 Jul 2001 08:17:31 +1000
On 09-Jul-2001, Norman Ramsey <firstname.lastname@example.org> 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 <email@example.com> | "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.