Tuple IFTI with implicit conversions

BCS ao at pathlink.com
Sat Oct 20 12:15:05 PDT 2007


Reply to Jari-Matti Mäkelä,

> Couldn't the polysemous values be used here? E.g. caller side calls
> the function with a set of possible type tuples. In the end the
> compiler could choose the best match(es) or throw an error on
> ambiguity. The char[] <-> char[n] conversion is particularly annoying
> even in very trivial code - a template doesn't sound like a good idea.
> 
> Approach with polysemous values could be extended in other ways. IFTI
> functions could be overloaded. One thing that has caused me some
> headache is the IsExpression - it seems to sweep under the carpet the
> fact that template parameters cannot do proper static predicate
> dispatching. I'd like to see a way to specify a compile time boolean
> function that defines whether the pattern matches or not (arithmetics
> with types should have proper semantics then - this could be extended
> elsewhere too, but I won't touch that here) - a general case could
> look like:
> 
> void myFun(T1 : predicate_1, ..., Tn : predicate_n)(type_1 param_1,
> ..., type_n param_n)
> 
> I don't think moveing the predicates to the fn parameter side (BCS's
> proposal) is a good idea since it's something different that D does
> now.
>

Yeah, I like that syntax a little better than mine (I never did like mine, 
to many T's) but I'm not clear on the semantics. How would it map the "used" 
types to the "accepted" types?

what I want is to work:

void TFn(T)(T a, T b){...}

// 'A' converts to 'B', 'B' doesn't convert to 'A' 

A a;
B b;
TFn(a, b);
TFn(b, a);

the first though is to map by position:

void TFn(T, U)(TypeFn!(T, U) a, TypeFn!(T, U) b){...}

but what if there a different number of template args than function args?

void TFn(V, T, U)(V v1, F!(T,U, V) a, V v2, F!(T,U) b){...}
 
now what?

what is needed is a way to get at explicitly bind something to the incoming 
type. An interesting note here is that the this is close to a system where 
the actual template args can be derived from what is given, this can result 
in fewer instances of the template.

Av get(Av : (uint N = Av.length, T = typeof(Av[0])))(T[] text)
{
   if(text.length < N) return null;
   return text[0..N];
}

TestFor!("hello")(str);  // same function
TestFor!("world")(str);  // in both cases


I'm not sure where this is all going, but I see a huge amount of power in 
letting the programer get ahold of the types and value that the user gives 
and play with them, particularly if this can work with the ITFI.





More information about the Digitalmars-d mailing list