digitalmars.D - type classes for selection of template variant
- spir (18/18) Dec 15 2010 Hello,
- Robert Jacques (3/22) Dec 15 2010 No new syntax is required: templates can already test whether two types ...
- Jonathan =?UTF-8?B?U2NobWlkdC1Eb21pbsOp?= (2/4) Dec 15 2010 No, interfaces imply overhead at runtime and they are only supported by
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
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.comNo 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
D does not need any new language feature: interfaces are perfect for that.No, interfaces imply overhead at runtime and they are only supported by classes.
Dec 15 2010