Home Documentation Download Blog Forum Projects
Label: ♦english ♦feature request

[578] To name the unnamed

Comment
I have a proposal related to the newly introduced algebraic types (disjoint union types).
Let's start with the issue first. Suppose I want to write a binary search routine for lists; the strict declaration should then look like this:
routine find(source: list<@T>, element: @T) => int;
Now let's suppose I want to use algebraic type for the list parameter to restrict the type of its elements, say, "list<int|long|float|double>". But what to do with the element parameter then? Apparently, there will be no way to match it's type to those of source ! The most natural solution seems to be in using aliasing, something like this:
routine find(source: list<int|long|float|double as @T>, element: @T) => int;
There is another case where such thing could be useful -- template classes. What if I want to set up restrictions on the template parameter? Again, the solution may come in form of aliasing:
class Item<int|string as @T>
{
var x: @T;
...
}
Not sure we need this feature so badly, but I still would like to hear your opinions and proposals :)
Comments
I have been thinking about this issue. But you are so quick to bring it up:)

The type form that I have been thinking for this looks like the following:
@T<int|long|float|double>
which means the type holder @T will hold one of the listed types.
Seems like an interesting idea. Just to add my 0.50$, I prefer TheTrueNightWalker's syntax, as in general I do prefer more words and less symbols, because they are easier to read and remember.
The middle in between both of you would be the following :-)
routine  find(source:  list<@T  asint|long|float|double>,  element:  @T)=>int;

Well, there is a minor problem with using as in type names, that is, your have to add blank spaces in type names, which is not very nice.
Do you mean "not nice" from a parser's viewpoint or from a user's viewpoint? If the latter, it is just a matter of taste, and it seems our tastes differ with regards to that point :-)
I meant from users' viewpoint. There is no problem for the parser. Now I am considering support both "@T<int||float||...>" and "@T as int||float||..." , and use "@T<int||float||...>" as the internal type name. The reason to put "@T" before the variant, it's because "@T as int or float or ..." would look more natural.
I'd prefer the syntax with "as" ; without angle brackets, it looks much better when used within templates or container types :) And it seems more readable too.

Change picture:

Choose file:

1234 5
67891011 12
131415161718 19
202122232425 26
2728293031

fu: A little bit game development in Dao! Thanks to ClangDao, it has become very easy to create bindings for C/ C++ libraries. The latest one i ... (May.14,07:08)

dao: Dao 1.2 Beta1 is released! After a very long time of development, the first beta release for Dao 1.2 is finally available ( http ... (May.06,23:37)

fu: ... Just to mention: a couple of demos (including the 2000 line one) has been successfully ported to IPho ... (May.19,02:43)

fu: ... Yes, it is getting mature, and more libraries and modules are coming out, hehe:) For GameKit, unfor ... (May.19,02:38)

Pompei2: ... This is cool news and really shows that ClangDao is getting mature, thumbs up. Too bad for this litt ... (May.18,09:17)

fu: ... Not completely, but mostly. New revisions will be regularly pushed to the repository on google code ( ... (May.08,22:38)

Pompei2: ... If I understand it correctly, you want to completely switch? If so then: (May.08,08:46)

This site is powered by Dao
Copyright (C) 2009-2012, daovm.net.
Webmaster: admin@daovm.net