Thread overview
A partial template application literal syntax
Sep 17, 2012
bearophile
Sep 17, 2012
Timon Gehr
Sep 17, 2012
Denis Shelomovskij
Sep 17, 2012
bearophile
Sep 24, 2012
Denis Shelomovskij
September 17, 2012
From this long Reddit post:
http://www.reddit.com/r/haskell/comments/zxcks/haskell_vs_f_vs_scala_a_highlevel_language/c68ybn1

I have seen this linked page:
https://github.com/non/kind-projector

Where it introduces a (fragile) Scala syntax like:
Tuple3[Int, ?, ?]

That is similar to this D, but it's usable in-place:
template IntFirst3(T2, T3) { alias Tuple!(int, T2, T3) IntFirst3; }

A comparable hypothetical D syntax, for partial template application:
Tuple!(int, ?, ?)

Being it usable in-place, you can use it as:

static asssert(is(Tuple!(int, ?, ?)!(double, float) ==
                  Tuple!(int, double, float)));

It's a fun syntax: Foo!?

Bye,
bearophile
September 17, 2012
On 09/17/2012 03:53 PM, bearophile wrote:
>  From this long Reddit post:
> http://www.reddit.com/r/haskell/comments/zxcks/haskell_vs_f_vs_scala_a_highlevel_language/c68ybn1
>
>
> I have seen this linked page:
> https://github.com/non/kind-projector
>
> Where it introduces a (fragile) Scala syntax like:
> Tuple3[Int, ?, ?]
>

Eiffel uses this for partial method application.
http://archive.eiffel.com/doc/online/eiffel50/intro/language/tutorial-12.html

> That is similar to this D, but it's usable in-place:
> template IntFirst3(T2, T3) { alias Tuple!(int, T2, T3) IntFirst3; }
>
> A comparable hypothetical D syntax, for partial template application:
> Tuple!(int, ?, ?)
>
> Being it usable in-place, you can use it as:
>
> static asssert(is(Tuple!(int, ?, ?)!(double, float) ==
>                    Tuple!(int, double, float)));
>

You cannot because multiple ! arguments are disallowed.

Parentheses do not help either because DMDs parser will interpret it as a deprecated C-style cast expression. (unless this is removed, the
claim that binary '!' makes parsing non-ambiguous is a myth.)

> It's a fun syntax: Foo!?
>
> Bye,
> bearophile

September 17, 2012
17.09.2012 17:53, bearophile пишет:
>  From this long Reddit post:
> http://www.reddit.com/r/haskell/comments/zxcks/haskell_vs_f_vs_scala_a_highlevel_language/c68ybn1
>
>
> I have seen this linked page:
> https://github.com/non/kind-projector
>
> Where it introduces a (fragile) Scala syntax like:
> Tuple3[Int, ?, ?]
>
> That is similar to this D, but it's usable in-place:
> template IntFirst3(T2, T3) { alias Tuple!(int, T2, T3) IntFirst3; }
>
> A comparable hypothetical D syntax, for partial template application:
> Tuple!(int, ?, ?)
>
> Being it usable in-place, you can use it as:
>
> static asssert(is(Tuple!(int, ?, ?)!(double, float) ==
>                    Tuple!(int, double, float)));
>
> It's a fun syntax: Foo!?
>
> Bye,
> bearophile

Just want to mention about existent (and more flexible than this syntax) library solution.
Search for `Bind` here:
https://bitbucket.org/denis_sh/misc/src/tip/stdd/typetuple.d

-- 
Денис В. Шеломовский
Denis V. Shelomovskij
September 17, 2012
Denis Shelomovskij:

> Just want to mention about existent (and more flexible than this syntax) library solution.
> Search for `Bind` here:
> https://bitbucket.org/denis_sh/misc/src/tip/stdd/typetuple.d

Its ddocs show this:

import std.traits;

static assert(is(staticBind!(CommonType, long, allArgs).Res!int == long));
static assert(!staticBind!(isImplicitlyConvertible, arg!0,   int).Res!long);
static assert( staticBind!(isImplicitlyConvertible, int  , arg!0).Res!long);

alias staticBind!(staticMap, Unqual, allArgs).Res UnqualAll;
static assert(is(UnqualAll!(const(int), immutable(bool[])) T) &&
              T.length == 2 && is(T[0] == int) && is(T[1] == immutable(bool)[]));


I have understood the meaning and usage of those "type lambdas" that use ? in Scala as soon I have seen them, while I don't get much from this noisy stuff :-(

Bye,
bearophile
September 24, 2012
18.09.2012 1:56, bearophile пишет:
> Denis Shelomovskij:
>
>> Just want to mention about existent (and more flexible than this
>> syntax) library solution.
>> Search for `Bind` here:
>> https://bitbucket.org/denis_sh/misc/src/tip/stdd/typetuple.d
>
> Its ddocs show this:
>
> import std.traits;
>
> static assert(is(staticBind!(CommonType, long, allArgs).Res!int == long));
> static assert(!staticBind!(isImplicitlyConvertible, arg!0, int).Res!long);
> static assert( staticBind!(isImplicitlyConvertible, int  ,
> arg!0).Res!long);
>
> alias staticBind!(staticMap, Unqual, allArgs).Res UnqualAll;
> static assert(is(UnqualAll!(const(int), immutable(bool[])) T) &&
>                T.length == 2 && is(T[0] == int) && is(T[1] ==
> immutable(bool)[]));
>
>
> I have understood the meaning and usage of those "type lambdas" that use
> ? in Scala as soon I have seen them, while I don't get much from this
> noisy stuff :-(
>
> Bye,
> bearophile

Yes, my library solution is rather ugly (but still doesn't know why it isn't as obvious as Scala's one). Just added a clearer one (if somebody needs this). Search for "Binds template arguments using format string." (second `Bind` template) here (if you want):
https://bitbucket.org/denis_sh/misc/src/tip/stdd/typetuple.d



To conclude:

Your proposal:
alias Tuple!(int, ?, ?) T;

My first solution:
alias staticBind!(Tuple, int, arg!0, arg!1).Res T;

My second solution:
mixin Bind!q{ Tuple!(int, %0, %1) T };



From docs:

Binds template arguments using format string.

Example:
----
import std.traits;

mixin Bind!q{ CommonType!(long, %*) CommonTypeToLong };
static assert(is(CommonTypeToLong!int == long));

mixin Bind!q{ isImplicitlyConvertible!(%0, int) isImplicitlyConvertibleToInt };
static assert(!isImplicitlyConvertibleToInt!long);

mixin Bind!q{ isImplicitlyConvertible!(int, %0) isImplicitlyConvertibleFromInt };
static assert( isImplicitlyConvertibleFromInt!long);

mixin Bind!q{ staticMap!(Unqual, %*) UnqualAll };
static assert(is(UnqualAll!(const(int), immutable(bool[])) T) &&
              T.length == 2 && is(T[0] == int) && is(T[1] == immutable(bool)[]));

-- 
Денис В. Шеломовский
Denis V. Shelomovskij