D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5109 - some advise
Summary: some advise
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P1 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-23 18:55 UTC by galaxylang
Modified: 2014-01-09 08:17 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description galaxylang 2010-10-23 18:55:56 UTC
I am from china and poor of english,i am sorry you may can't
understand what i am meaning.
Recently,i am study a lite about haskell,so i think now D's
template is some like a functional program evolution form c++.
because i find some restrict,i think it's still in a low-level
for we still think it in a c++ way.Should we drop more from c++,
then go into a high-level template program?

now i want to point out what i found which is can't tolerance and some 
i think should be work out.

1:
this code don't work because the name query somelike  not a bidirection
way,[alias ReturnType!(T) Out],can't resolve the opCall
 
class monad(alias T)
{
	alias ReturnType!(T) Out;//*****

}

class	maybe(T):monad!(maybe!T)
{
	auto	opCall(maybe!T)
	{
		alias maybe!long R;
		return R.init;
	}
}
there is another sample:
struct B(T)
{
}
alias B!(C) BC;//identifier 'C' is not defined!
alias B!int C;


2:
add parital template feature
struct P(A...)
{
}
alias  P!int P1;
P1 p1;//instance of P!int
alias P1!long P2;
P2 p2;//intance of P!(int,long)

this feature will make D has the power to write a template functional
library,and change D into a high-levle program language.
Comment 1 bearophile_hugs 2010-10-25 15:51:38 UTC
(In reply to comment #0)
> I am from china and poor of english,i am sorry you may can't
> understand what i am meaning.

I think we are able to understand what you mean.


> this code don't work because the name query somelike  not a bidirection
> way,[alias ReturnType!(T) Out],can't resolve the opCall
> 
> class monad(alias T)
> {
>     alias ReturnType!(T) Out;//*****
> 
> }
> 
> class    maybe(T):monad!(maybe!T)
> {
>     auto    opCall(maybe!T)
>     {
>         alias maybe!long R;
>         return R.init;
>     }
> }

This seems a valid bug report or enhancement request.


> there is another sample:
> struct B(T)
> {
> }
> alias B!(C) BC;//identifier 'C' is not defined!
> alias B!int C;

This is a bug report, and I think it's already present somewhere in Bugzilla.

In future I suggest you to put just one bug report (or enhancement request) for each Bugzilla entry.


> 2:
> add parital template feature
> struct P(A...)
> {
> }
> alias  P!int P1;
> P1 p1;//instance of P!int
> alias P1!long P2;
> P2 p2;//intance of P!(int,long)
> 
> this feature will make D has the power to write a template functional
> library,and change D into a high-levle program language.

This is another different enhancement request. I have never seen it before. It looks cute. Are you able to show one or more possible usages of it?

I will soon link this bug report in the main D newsgroup.
Comment 2 galaxylang 2010-11-04 22:13:55 UTC
I have not on net for a long time,because i have not a network at home,
(network is still very expensive in our country in our country :)
and i am now prepare for some examine.so i submit a new issue to attract
your notice,and some new i advise.
http://d.puremagic.com/issues/show_bug.cgi?id=5067
Comment 3 christoph@nerdtools.de 2014-01-09 03:31:58 UTC
D is actually able to do something like partial templates.
Here is an example that works:

struct P(A...)
{
	alias Args = A; 
}

alias  P!int P1;
P1 p1; // P!int

alias P!(P1.Args,long) P2;
P2 p2; // P!(int, long)


void main() {
	writeln(typeid(P2));  // Output: main.P!(int, long).P
}