Help understanding abstracts

What is the purpose of Abstracts? That is, I see that the manual says:

“An abstract type is a type which is actually a different type at run-time. It is a compile-time feature which defines types “over” concrete types in order to modify or augment their behavior”

but I don’t understand what the motivation is for this feature.

When would I want to use an abstract?


1 Like

Thank you, Aleks! Working on learning some prerequisites to better understand that article! :slight_smile:

There are some nice articles about some practical uses for abstracts here too:


Abstract types in Haxe allow creating pure compile-time abstractions (hence the name) over a concrete run-time type. Basically, this way you can introduce new types without wrapping values inside objects at run-time (and thus hurting performance).

Also, abstract support some extra features that are currently not available for other types, like operator overloading and implicit type conversion methods.

1 Like

Thanks, Dan! Wow, I hadn’t heard of abstracts before. I’m amazed that the compiler can do this for us. I don’t have a use for it right now, but will definitely keep this in mind.