waneck / testrepo

0 stars 0 forks source link

Issue 1826 - Additional constraint types - haxe #1826

Open waneck opened 11 years ago

waneck commented 11 years ago

[Google Issue #1826 : http://code.google.com/haxe/issues/detail?id=1826] by si...@haxe.org, at 2013-05-17T22:24:10.000Z It would be nice if we could get a few more "constraint types" like EnumValue, Class and Enum: Function: unifies with any function Abstract: unififes with any abstract type FlatEnum: unififes with enum instances if all constructors of its enum type have no arguments [something to replace the Dynamics in Reflect]: unifies with {}, Class and Enum, i.e. anything that has fields (alternatively we can make {} unify with Class and Enum)

I'm thinking about adding a haxe/Constraints.hx file containing these.

waneck commented 11 years ago

[comment from back2dos@gmail.com, published at 2013-05-19T06:34:32.000Z] Very good idea.

But for one, I'm not sure Abstract really makes sense. The only usage I see is ExprOf. At runtime however, this type carries no meaning at all unless I'm missing something. Also, it would be nice to explicitly have a type only for instances, that would not accept anonymous objects. I'd call it ClassValue, because I think Instance is more common (and meaningful in many contexts) and it's also consistent with EnumValue.

Lastly, having Class and Enum unify with {} seems rather sensible to me. When accessed in an untyped manner, they do behave exactly as object. Or is this behavior only incidental?