On Fri, 2006-10-06 at 12:08 +1000, skaller wrote:
> There are several features of typeclass that are mandatory
> to make them actually useful.
The second feature is trickier: partial specialisations.
Let us suppose we want to charactise a sequential
container such as vector or list. We need to write:
typeclass Seq[c,t] {
virtual fun first: c -> opt[t];
}
for example (in reality we might use iterators).
Now the problem is we want something like:
instance Seq[c,t where c==vector[t]] {
fun first: c -> t = "$1.pop_front()";
}
This requires TWO features: constraints, and partial
specialisations (which are related of course).
The partial specialisation issue is clear: we want
to characterise vector, not vector[int].
The above form is a special case. Here is a more
general case:
typeclass X[u,v] ...
instance[t] X[t*t,t+t] ...
In this case, the instance is a partial specialisation
of the original typeclass.
How should other specialisatons relate to this?
One answer is: the same way as overloading: the most
specialised instance is chosen... hmm..
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language