daokoder / dao

Dao Programming Language
http://daoscript.org
Other
198 stars 19 forks source link

Enhancement: support auto-conversion of the none type in the ternary operator #506

Open dumblob opened 9 years ago

dumblob commented 9 years ago

We already have some support for auto-conversion of disjoint union types containing none, but the ternary operator doesn't support it. Right now, the following will check type in runtime:

load web.html import html
uri = ''
x = fragment {
  anchor(href=%uri ? (@T)uri : (@T)none)
}

but the following will throw an error in compile time:

load web.html import html
uri = ''
x = fragment {
  anchor(href=%uri ? uri : none)
}

Note, that the href named argument of anchor currently accepts only string, which might change based on the issue https://github.com/daokoder/dao-modules/issues/78 .

Night-walker commented 9 years ago

I don't think it's a good idea. It would be type mangling which may easily lead to errors. If this functionality is deemed important, I'd rather welcome a dedicated operator which accepts a condition and a value of type @T, yielding @T|none.