D's type classes pattern ?

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Mar 25 01:55:13 PDT 2015


matovitch:

> I am curious to know how isInputRange is implemented since I
> wanted to do kind of the same but I am afraid it's full of 
> (ugly)
> traits and template trickeries where haskell type classes are
> quite neat and essentially a declaration of an interface.

Take a look at the sources and learn. They are sometimes tricky 
to get right, but it's not a problem of ugly syntax.


> I wondered if you could check statically that the type could
> implement an interface *if it wanted to* that is, without
> inheriting it...

Template constraints don't require inheritance.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list