type classes and generality
Mon, 09 Jul 2001 21:24:32 -0400
"Alexander V. Voinov" wrote:
> Hi All,
> Fergus Henderson wrote:
> > Ah, now I think I understand your problem. You want to `random' to
> > generate random numbers that span all the possible values of the type
> > within the range [0, 1], or at least a substantial subset, but the "Real"
> > class doesn't let you generate any numbers other than integers.
> > The above approach will give you random numbers from `random', but they
> > will only ever be 0 or 1, so maybe they are not as random as you needed! ;-)
> Each pseudorandom generator generates a countable sequence of values,
> which is isomorphic to a sequence of integers. In good old (Turbo)C we
> got something between 0 and MAXINT and then divided by (double)MAXINT.
> Can't _this_ be done in Haskell?
Of course it can be done, but not in class Real, you have to be in Fractional.
I'm not sure why Real would be the class of choice for this problem anyway.
I'd think that Fractional or RealFrac would be more appropriate.