-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose intersection types? #120
Comments
No plans to do that at this point. This kind of feature interacts with the entire type system in super subtle ways, and as these things are added, they compound (i.e. they add complexity to the features that were there before). I'm still working out the kinks with union types, because I felt that one was inescapable, but for intersection types I'll avoid them for as long as I can — I'd rather add something specific for record/object inheritance instead and not open that Pandora's Box. (See @mascarenhas's comments on #97 to the effect that adding super general constructs as alternatives to OOP end up more complicated than adding OOP itself.) |
I still feel true intersection would be a nice addition |
With next out there's interfaces now, but I do not feel they cut it local record x
a: string
b: string
end
local record y
b: number
c: string
end
local type z = x & y
-- aka
local record z
a: string
b: number -- y overrides x
c: string
end Almost all type systems with some form of record or struct type allow some form of type intersection it would be incredibly valuable |
I don't usually critique every feature suggestion, but a quick exception: This would mean that For reference, this is how an example like the above looks like with interfaces in Teal '24 — incompatible fields need to be stated explicitly, but compatible fields can be inherited: local interface IX
xa: string
xb: string
xc: string
end
local interface IY
ya: string
yb: string
yc: string
end
local record X is IX
b: string
end
local record Y is IY
b: number
end
local record Z is IX, IY
b: number
end
--[[
-- this produces a record with these fields,
-- but Z also satisfies `Z is IX` and `Z is IY`.
local record Z
xa: string
xb: string
xc: string
ya: string
yb: string
yc: string
b: number
end
]] |
Wait that is essentially record intersection (or rather more like traits) |
Yes, it is more like traits (and not exactly like record intersection, but it can be used for similar goals)
oh, you're right! None of the examples in |
Right now, Teal supports intersection types for function overrides inside record definitions.
Are there any plans to expose an
&
operator for creating new intersection types? I think this could be useful for simulating inheritance:The text was updated successfully, but these errors were encountered: