Implementing Haskell's Type-Level Quicksort in D

bearophile bearophileHUGS at lycos.com
Thu Feb 13 18:41:11 PST 2014


Meta:

> alias list1 = Cons!(Three, Cons!(Two, Cons!(Four, Cons!(One, 
> Nil))));
>
> alias numlHead(L: Cons!(a, b), a, b) = a;
>
> alias numlTail(L: Cons!(a, b), a, b) = b;
>
>
> But the compiler is complaining loudly about a mismatch:
>
> /d43/f234.d(39): Error: template instance numlHead!(list1) does 
> not match template declaration numlHead(L : Cons!(a, b), a, b)

See a recent thread of mine:
http://forum.dlang.org/thread/vlwgufdlpjgewpnnhkma@forum.dlang.org

Currently I think you have to accept types and aliases with a 
regular template syntax, and verify the types and kinds with 
template constraints. Something like (untested):

template numlTail(C) if (TemplateOf!(C, Cons)) {
     alias numlTail = TemplateArgsOf!(C)[1];
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list