Should the comma operator be removed in D2?
Yigal Chripun
yigal100 at gmail.com
Wed Nov 18 14:00:00 PST 2009
Ellery Newcomer wrote:
foo(a, b) is identical to foo(t);
>
> does ML have any equivalent of template parameters? eg
>
> foo!(1,int);
>
I'd suggest reading the wikipedia page about ML.
in short, ML is a strongly, statically typed language much like D, but
doesn't require type annotations. it uses the Hindley-Milner type
inference algorithm (named after its creators) which infers the types at
compile-time.
here's a naive factorial implementation in ML:
fun f (0 : int) : int = 1
| f (n : int) : int = n * f (n-1)
you can provide type annotations as above if you want to specify
explicit types.
here's another function:
fun foo (n) = n + n
if you use foo(3.5) the compiler would use a version of foo with
signature: real -> real
but if you use foo(4) the compiler will use a version of foo with
signature int -> int
note that I didn't need to specify the type as parameter.
foo's signature is actually: `a -> `a which is like doing in D:
T foo(T) (T n) { return n + n; } but unlike ML, in D/C++ you need to
provide the type parameter yourself.
does that answer your question?
More information about the Digitalmars-d
mailing list