[mercury-users] functions returning in values?

MCL boris at aaron.ls.fi.upm.es
Wed May 9 00:41:12 AEST 2001


>> If you look at the float library, say, you will see mode collections
>> for the basic arithmetic operations that allow you to compute the
>> third argument of X = Y @ Z (for @ in {+,-,*./}) given any two
>> arguments.
>> 
>> This can be quite handy.  For example,
>> 
>> :- pred fahrenheit(float) = float.
>> :- mode fahrenheit(in) = out is det.
>> :- mode fahrenheit(out) = in is det.
>> 
>> fahrenheit(Centigrade) = Fahrenheit :-
>> 	Fahrenheit = 32.0 + (9.0/5.0 * Centigrade).
>> 
>> Now, F = fahrenheit(100.0) has the solution F = 212.0 while
>> 212.0 = fahrenheit(C) has the solution C = 100.0.
>> 
>> Interestingly Prolog's is/2 doesn't let you do this sort of thing.

    Certainly not; it is easy to program, though.  It is a builtin if
you have a CLP variant.


>> An interesting application of this stuff is in cryptography: you only
>> have to describe the cipher function in Mercury and supply the
>> appropriate modes and Mercury will give you both enciphering and
>> deciphering, halving the likelihood of you introducing errors in your
>> code.

    I have to doubt it: any decent cryptography scheme should not be
reversible that easy---unless you want to enumerate all possible clear
messages.

        MCL

_________________________________________
Noalias must go.  This is non-negotiable.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list