S.D.Mechveliani, you wrote:
> 
> will you, please, analyze the following suggestion.
> Let we call it the 
>                   extended type context attachement.

This feature -- specialization, or partial specialization, of polymorphic
functions -- is quite important.  Alexander Stepanov (designer of the C++
Standard Template Library) has been explaining this on a recent thread
crossposted to comp.lang.functional amoung others.

I haven't thought about it too hard, but I have thought about it a bit,
and I don't see any way of achieving it without either (a) basically giving
up separate compilation or (b) requiring expensive computations at runtime
to figure out which specialization to invoke.  (C++ chose (a).)

> Suggestion: 
> 
> ------------------------------------------------------------------
> to make it possible to srcipt like this:
> 
> det :: AddMul a => Matrix a -> a
> det                mM       =  expandByRow mM  where ...
> 
> det :: (AddMul a,Div a) => Matrix a -> a
> det                        mM       =  gaussElimination mM 
>                                                          where ...

I don't think this syntax is going to work.  For example, how does it
interact with separate compilation?  I think the syntax should explicitly
indicate that the second definition is a specialization.

Here's another possible alternative way of achieving a similar effect:

det :: AddMul a => Matrix a -> a
det mM | class mM Div = expandByRow mM       where ...
det mM | otherwise    = gaussElimination mM  where ...

Here `class <expr> <type-class>' is a new builtin boolean expression
that returns true iff the expression has a type that is an instance
of the specified type-class.  [Or perhaps it should be written as
`instance <type-class> (type_of <expr>)', e.g. `instance Div (type_of mM)'?.
That would scale better to multi-parameter type classes.  In case you
hadn't noticed yet, I'm making this up as I go along.]

This alternative is still going to be difficult to implement
in the presence of separate compilation.

-- 
Fergus Henderson <[EMAIL PROTECTED]>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]         |     -- the last words of T. S. Garp.



Reply via email to