Hi there. What I’m trying to achieve is a way of describing a database entity, but wrapping the native Types in classes. This is the code I have so far -
public type Type<T> = {
get : () -> T;
set : T -> ();
sanitise : () -> T;
validate : () -> Bool;
};
public class FloatType() {
public var value : Float = 0;
public func get() : Float { value };
public func set(v : Float) {};
public func sanitise() : Float { value };
public func validate() : Bool { true };
};
public class IntType() {
var value : Int = 0;
public func get() : Int { value };
public func set(v : Int) {};
public func sanitise() : Int { value };
public func validate() : Bool { true };
};
and I’d like to use these with a hierarchy of custom functions -
public func Area() : Type<Float> { FloatRange(0.001, 1e6) }; // m^2,
public func Density() : Type<Float> { FloatRange(0.001, 1e6) }; // kg/m^3
public func Distance() : Type<Float> { FloatRange(0.001, 500) }; // m
public func Friction() : Type<Nat> { Percent() }; // %
public func Hardness() : Type<Nat> { NatRange(1, 15) }; // H (Mohs + 5 extra fantasy level)
public func Mass() : Type<Float> { FloatRange(0.001, 1e6) }; // kg
public func Opacity() : Type<Nat> { Percent() }; // %
public func Resonance() : Type<Nat> { Percent() }; // % (fantasy world concept)
public func Temperature() : Type<Nat> { IntRange(-200, 10,000) }; // °C
public func Velocity() : Type<Float> { FloatRange(0.01, 500) }; // m/s
public func Volume() : Type<Float> { FloatRange(0.01, 1e6) }; // m^3
and the Type itself would look like :
public class Base() = {
var created = Types.Time();
var lastModified = Types.Time();
};
// Ability
public type AbilityID = Types.ID;
public class Ability() = {
// var _base: Base = ???;
// fields
var name = Types.EntityName();
var description = Types.Description();
var something = Types.FloatRange(0.01, 500);
// relations
//icon : IconID;
};
I wondered if anybody had any feedback on this approach. Also is there inheritance or composition in the language yet or is it planned?
Thanks again!