[mercury-users] a typeclassful random.m

Julian Fondren ayrnieu at gmail.com
Fri Feb 23 17:15:57 AEDT 2007


On 2/21/07, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> On Wed, 21 Feb 2007 doug.auclair at logicaltypes.com wrote:
> > Put another way: perhaps the protocol can be modified to
> > provide the user a simpler typeclass specification of only one
> > argument for the majority (in my case, for all) of uses?

I haven't found a way.

> I think that Julian's typeclass is wrong w.r.t the functional
> dependencies.  The seed type should be functionally dependent on the state
> of the random number generator but not the other way around.

Having the types depend on each other forces you to use specific
types for each (and not simply string or pair(int, int) for the
seed when only the seed depends on the RNG state, and not simply
int or list(int) or some bizarre thing when only the RNG state
depends on the seed), but it frees you to write code like this:

main(!IO) :-
    some [!DRNG] (
        open(device_name("/dev/urandom"), !:DRNG, !IO),
        next(A, !DRNG, !IO),
        next(B, !DRNG, !IO),
        next(C, !DRNG, !IO),
        close(!.DRNG, !IO),
        seed(tausworthe3_seed(A, B, C), PRNG),
        spew(PRNG, !IO)
    ).

-- without one or two `with_type`s, depending on spew/3.

Cheers,
Julian
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list