[mercury-users] boolean expressions from semidet predicates
Richard A. O'Keefe
ok at cs.otago.ac.nz
Fri May 19 10:58:46 AEST 2006
"Jonathan Morgan" <jonmmorgan at gmail.com> wrote:
(however,
no language that I know of provides the ability to make a function
available for all types over which a particular operator is defined,
without first requiring them to make that type an instance of some
typeclass or interface).
C++.
template <typename T>
T f(T x, T y) {
return (x - y) * (x + y);
}
This function is usable for any type T that provides +, -, and * .
The Clean functional programming language comes pretty close.
It makes each individual arithmetic operation into a typeclass,
named after the operation, so you can write
f :: t -> t -> t | + , - , * t
f x y = (x - y) * (x + y)
In StdClass.dcl we find
class PlusMin a | + , - , zero a
class MultDiv a | * , / , one a
class Arith a | PlusMin , MultDiv , abs , sign , - a
showing that more Haskell-like typeclasses can be built up by inheritance
from single-operation typeclasses.
This is actually a DARNED good idea, because in Haskell you are stuck
with the operation bundles they already decided on, and if you have something
that doesn't quite fit (a situation I've been in) there is nothing you can do.
In Clean you can put together the bundle you need.
--------------------------------------------------------------------------
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