type classes and generality
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? Norman
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.
Norman Ramsey writes: : | 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? How about the default-implementations-as-external-functions approach Marcin suggested, adapted for Real instead of Bounded and Enum? http://www.mail-archive.com/haskell@haskell.org/msg05658.html
participants (3)
-
Fergus Henderson -
Norman Ramsey -
Tom Pledger