type classes for selection of template variant

spir denis.spir at gmail.com
Wed Dec 15 04:58:36 PST 2010


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



More information about the Digitalmars-d mailing list