|
|
Label: ♦english
♦feature request
Nightwalker
created at Tuesday, 2011-02-01, 23:07:12
Nightwalker
modified at Tuesday, 2011-02-01, 23:18:42
6 Replies, 1411 Hits
I have a proposal related to the newly introduced algebraic types (disjoint union types).
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;
class Item<int|string as @T>
Not sure we need this feature so badly, but I still would like to hear your opinions and proposals :){ var x: @T; ... } Source URL:
http://www.daovm.net/space/dao/thread/578
Comments
fu commented at Wednesday, 2011-02-02, 03:13:20
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.
Pompei2 commented at Wednesday, 2011-02-02, 08:42:47
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 as int|long|float|double>, element: @T) => int;
fu commented at Friday, 2011-02-04, 05:43:34
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.
Pompei2 commented at Friday, 2011-02-04, 08:02:47
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 :-)
fu commented at Saturday, 2011-02-05, 19:16:46
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.
Nightwalker commented at Saturday, 2011-02-05, 19:36:57
Nightwalker modified at Saturday, 2011-02-05, 19:37:35
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.
|
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) |