Thanks so much for the attention to this post , I appreciate that!
my use case is simple, I wanted to have subset of the language to use it to define model schema with less code possible.
my background is python and we used to have simple toml format for our schemas
something like
model_name = "person"
name = "myname" (S) # (S) means string
age = 30 (I) # I means Integer
created_at = 1234566 (T) # T is time stamp / epoch
the previous schema definition is simple and into the point, simple toml, I don’t use have to use complex programming logic
but we needed a special parser for this to parse and create proper objects
I wanted to achieve same simplicity of schema using crystal by defining my own data types subset
alias I = Int32?
alias S = String
alias F = Float64?
alias T = TimeStamp?
and I wanted my models/schemas to be defined in terms of these subset
struct Logs
property url : URL = "blah blah"
property time : T = 1234567
property logs : S = "blah blah"
end
so I was thinking in my use case for a time / epoch it’s just an integer , so I wanted to define my type T / TimeStamp to act like integer directly
I can compare it with another timestamp , so I can use the operators <. >. … directly
and in the same time I don’t have to do something like property time : T = T.new 1234567
I understand it’s kind of syntactic sugar, but I was wondering if there’s simple way to have it
In python you could do anythin with any datatype forinstance
In [16]: class TestClass(int):
...: def __new__(cls, *args, **kwargs):
...: return super(TestClass, cls).__new__(cls, 5)
...:
In [18]: tc = TestClass()
In [19]: tc == 5
Out[19]: True
In [20]: tc == 6
Out[20]: False