User loginNavigation |
crazy PL idea: prescriptive trait inferenceI've been working with a type system where type requirements are not actually checked, but added automatically to the program as needed. Such a type system can better support for bottom-up programming, but also allows for lots of small types (like mixins) in a library without the requiring programmers to tediously compose their objects. As a small example, consider a UI library with various kinds of panels that vary depending on how they manage layout: trait Widget(c: Panel) { ... } This language has no classes, just mixin-like traits. The :: operator means exclusive class-like inheritance, meaning Canvas and Dock cannot both be extended by the same panel object, while the : operator means normal mixin inheritance as in Scala. Canvas supports manual widget positioning, while dock allows the widget to be docked at the edge or center of the panel. We express this by defining two new kinds of widgets that exist in each panel:
Now, we can define a program using just panel and widget: When this code is compiled, "w" implicitly extends CanvasWidget because Position was accessed on it, which incidentally causes "p" to implicitly extend Canvas. The inference occurs at compile time, p is a canvas from the moment it is created. All abstractions exist in a flat space and are somehow uniquely named so the programmer can select them (think wiki's disambiguation pages). Inference can then occur because the user selected a specific abstraction whose typing requirements are known, as opposed to the other way around where the type determines how a name is resolved. The usability benefits come from the user not having to know about special kinds of widgets and panels; rather they can focus on what they want to do rather than how to enable that. In general, we could then build libraries with hundreds of little traits as an extreme form of "batteries included," where the user need not be aware of most of these traits as they are applied automatically as needed. Conflicts can arise if inference requires an object to extend two incompatible traits; e.g., I'm calling this prescriptive trait inference as an alternative to type inference which acts to catch errors rather than build programs; although this might be a bit unfair since implicit coercions driven by type inference can actually cause computation to occur (say in Scala). I want to go further on this design and build a more general language, which involves tackling the following problems:
Ah, this post is way too long; hopefully this doesn't come off as a brain dump. Anyways, I would appreciate some early feedback before I go off and do a general purpose language (I'm off to Krabi tomorrow, but I can't stop thinking about this :) ). By Sean McDirmid at 2012-01-17 11:42 | LtU Forum | previous forum topic | next forum topic | other blogs | 17262 reads
|
Browse archives
Active forum topics |
Recent comments
23 weeks 23 hours ago
23 weeks 1 day ago
23 weeks 1 day ago
45 weeks 2 days ago
49 weeks 4 days ago
51 weeks 1 day ago
51 weeks 1 day ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago