www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - type classes for selection of template variant

reply spir <denis.spir gmail.com> writes:
Hello,


see http://en.wikipedia.org/wiki/Type_class=20

I have tried several times to express the idea of using intervaces (only) f=
or template case selection. Instead of a combination of really penible & ha=
rdly 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 co=
nstraints, like the following (defining an interface for types that support=
 '=3D=3D', but not comp)
    interface EqualityOnly : Equality !: Comparable {}=20


Denis
-- -- -- -- -- -- --
vit esse estrany =E2=98=A3

spir.wikidot.com
Dec 15 2010
next sibling parent "Robert Jacques" <sandford jhu.edu> writes:
On Wed, 15 Dec 2010 07:58:36 -0500, spir <denis.spir gmail.com> 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.
Dec 15 2010
prev sibling parent Jonathan =?UTF-8?B?U2NobWlkdC1Eb21pbsOp?= <devel the-user.org> writes:
 D does not need any new language feature: interfaces are perfect
 for that.

classes.
Dec 15 2010