Typedefs?

Monkey Forums/Monkey Programming/Typedefs?

Samah(Posted 2012) [#1]
Mark,
Is it possible for us to get a Typedef keyword? Basically just use it as an alias for another type. This would give us the ability to change the type of a value anywhere.

Trans can convert it internally before outputting code. It could even be a preprocessor keyword.

#Typedef HealthType=Int

Class Unit
  Field health:HealthType

  Method SetHealth:Void(health:HealthType)
    Self.health = health
  End
End

This would be the same as simply using Int. If in the future you want to use a float to store health, it's as easy as changing the typedef rather than changing all references to the health field.


ziggy(Posted 2012) [#2]
Why don't you use Alias
EDIT: I see it does not work with non-class based datatypes other than String, wich at the same time produces some compilation errors.


Samah(Posted 2012) [#3]
I guess the goal then should be to just make Alias work with primitives (and String, which is debatably a primitive).