To date, I've been using D in much the same way I used C++, without heavy use of templates.  Now I'm trying out a more functional style using std.algorithm.  However I'm pretty much stuck at the first hurdle: map.  With type inference, this works:<div>
<br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div>import std.algorithm;</div><div>import std.stdio;</div><div><br></div><div>void main() {</div><div>  auto start = [1,2,3,4,5];</div>
<div>  auto squares = map!((a) { return a * a; })(start);</div><div>  writeln(squares);</div><div>}</div></blockquote><div><br></div><div>Without type inference (obviously necessary beyond trivial examples), it'd be nice to do:</div>
<div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>import std.algorithm;</div></div><div><div>import std.stdio;</div></div><div><div><br></div></div>
<div><div>void main() {</div></div><div><div>  int[] start = [1,2,3,4,5];</div></div><div><div>  int[] squares = map!((a) { return a * a; })(start);</div></div><div><div>  writeln(squares);</div></div><div><div>}</div></div>
</blockquote><div><br></div><div>but this gives "Error: cannot implicitly convert expression (map(start)) of type Result to int[]".  That opaque type "Result" is weird (not parameterized on "int"?), but OK, let's try that:</div>
<div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>import std.algorithm;</div></div><div><div>import std.stdio;</div></div><div><div><br></div></div>
<div><div>void main() {</div></div><div><div>  int[] start = [1,2,3,4,5];</div></div><div><div>  Result squares = map!((a) { return a * a; })(start);</div></div><div><div>  writeln(squares);</div></div><div><div>}</div></div>
</blockquote><div><br></div><div>gives "undefined identifier Result".  Not sure why, but OK.  I can't see examples in the docs of explicit type declarations -- annoyingly they all use "auto".</div>
<div><br></div><div>However, they do tell me that map "returns a range".  Assuming all definitions of ranges are in std.range, there's no such thing as a "Range" interface, so it's not that.  The most general interfaces I can see are InputRange(E) and OutputRange(E).  It certainly can't be an OutputRange, so I guess it must satisfy InputRange, presumably type-parameterized with "int".  So this should work:</div>
<div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>import std.algorithm;</div></div><div><div>import std.stdio;</div></div><div><div>import std.range;</div>
</div><div><div><br></div></div><div><div>void main() {</div></div><div><div>  int[] start = [1,2,3,4,5];</div></div><div><div>  InputRange!int squares = map!((a) { return a * a; })(start);</div></div><div><div>  writeln(squares);</div>
</div><div><div>}</div></div></blockquote><div><br></div><div>But the compiler complains "cannot implicitly convert expression (map(start)) of type Result to std.range.InputRange!(int).InputRange".  That's weird, because "std.range.InputRange!(int).InputRange" doesn't even look like a type.</div>
<div><br></div><div>I've tried all manner of combinations here, but nothing works.  Seems like there's something fundamental I'm not understanding.</div>