On Wed, 15 Dec 2010 07:58:36 -0500, spir <[email protected]> wrote:
Hello,
see http://en.wikipedia.org/wiki/Type_class
I have tried several times to express the idea of using intervaces
(only) for template case selection. Instead of a combination of really
penible & hardly readible is() expressions and adhoc functions like
isRandomAccessRange. (No chance in these trials ;-)
Just discovered this idea is actually the same as 'type classes'
introduced in Haskell (not that I'm a fan of functional programming,
just stepped on the article by chance).
D does not need any new language feature: interfaces are perfect for
that.
Maybe the syntax could be slightly extended to allow expressing negative
constraints, like the following (defining an interface for types that
support '==', but not comp)
interface EqualityOnly : Equality !: Comparable {}
Denis
-- -- -- -- -- -- --
vit esse estrany ☣
spir.wikidot.com
No new syntax is required: templates can already test whether two types
are similar in a 'duck' sense today, thanks to compile time reflection.