D vs Rust: function signatures

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Wed Apr 30 00:59:04 PDT 2014


On Wednesday, 30 April 2014 at 01:38:46 UTC, Narrator wrote:
> The unbelievable amount of time and energy that's been spent 
> discussing the smallest syntax, you would think that D would, 
> at the very least, have better looking function signatures, but 
> it doesn't.
>
> auto zip(Ranges...)(Ranges ranges) if (Ranges.length && 
> allSatisfy!(isInputRange, Ranges));
> auto zip(Ranges...)(StoppingPolicy sp, Ranges ranges) if 
> (Ranges.length && allSatisfy!(isInputRange, Ranges));
>
> fn zip<B, U: Iterator<B>>(self, other: U) -> Zip<Self, U>
>
>
> auto chain(Ranges...)(Ranges rs) if (Ranges.length > 0 && 
> allSatisfy!(isInputRange, staticMap!(Unqual, Ranges)) && 
> !is(CommonType!(staticMap!(ElementType, staticMap!(Unqual, 
> Ranges))) == void));
>
> fn chain<U: Iterator<A>>(self, other: U) -> Chain<Self, U>
>
>
> template map(fun...) if (fun.length >= 1)
> auto map(Range)(Range r) if (isInputRange!(Unqual!Range));
>
> fn map<'r, B>(self, f: |A|: 'r -> B) -> Map<'r, A, B, Self>
>
>
> template filter(alias pred) if (is(typeof(unaryFun!pred)))
> auto filter(Range)(Range rs) if (isInputRange!(Unqual!Range));
>
> fn filter<'r>(self, predicate: |&A|: 'r -> bool) -> Filter<'r, 
> A, Self>
>
>
> MaxType!(T1, T2, T) max(T1, T2, T...)(T1 a, T2 b, T xs) if 
> (is(typeof(a < b)));
>
> pub fn max<T: TotalOrd>(v1: T, v2: T) -> T

I don't think a single one of those signatures are equivalent.

Also, bear in mind that those if() constraints contain arbitrary 
code (as long as it can be evaluated at compile-time), so they 
are very flexible.


More information about the Digitalmars-d mailing list