Simple type system oriented question

I'd think I want to allow a function with this type:

proc(class T cls) : T

And I want such functions to support type subclasses. For a simple instantiating example:

proc myfun(class Employee empcls) : Employee
Manager m = myfun(Manager);


class Manager(Employee)
bonus : Dbl = 2.5 * salary; // :-)

Is this "principle of least surprise"? commonplace? or are there gotchas I'm not thinking about.

Thanks much.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Let me paraphrase. Does

Let me paraphrase. Does subclassing imply subtyping? Try googling for the substitution principle: is the substitution principle a formal corollary of the principle of least surprise?

I can't tell whether this is a homework assignment or an honest question, so that's about as far as I'm willing to go.

Thanks! - and I'm 42 years old (not homework....)

Your paraphrase points me in the right direction I think.

OT - I've had a chronic illness for ~4 years that impairs left brain function among many other things; haven't been able to write a 100 line Python script, or work at all for that matter. My "job" has been going to doctors and watching TV.

But about 3 months ago, something changed radically and ever since, for no obvious reason, I've been feverishly working on - a language spec and compiler! Haven't grokked anything like this since the early '90s. Maybe my left brain function is only up to CS undergrad level, but given my circumstances, I'll take it :-)

Thanks again! LtU is a *wonderful* site!