User loginNavigation |
Interfaces vs. Type ClassesI've recently been looking at a notion of interfaces for BitC. The language already has type classes in the style of Haskell, with all of the pros and cons of these. The deeper my dive into interfaces, the more confused I became about the difference between interfaces and type classes. This either means that I'm hopelessly confused or that I've stumbled into something useful. I'm sure the LtU audience can explain my confusion. :-) BitC has object-style methods in a syntactic sense, but no virtual methods or inheritance. In such a language, object methods are sugar. We also have a notion of interfaces, currently called "capsules". A capsule provides existential encapsulation of an underlying object combined with a known set of methods. In contrast to Java-style interfaces, a capsule type has an explicitly invocable constructor. This means that a capsule can have non-default instantiations for a given underlying type T. Capsule constructor arguments corresponding to method initializers are constrained to be compile-time evaluable. This has the consequence that every capsule "method table" is a compile-time constant in the same way that every type class instance method table is a compile-time constant. Capsules may have either static of conventional methods. A static is method does not receive or require a reference to the encapsulated object. The lifetime of a capsule instance is guaranteed not to exceed the lifetime of the object (if any) that it encapsulates. Q: How is a capsule type consisting exclusively of static methods different from a type class, if at all? By shap at 2014-01-04 05:49 | LtU Forum | previous forum topic | next forum topic | other blogs | 6543 reads
|
Browse archives
Active forum topics |
Recent comments
23 weeks 2 days ago
23 weeks 2 days ago
23 weeks 2 days ago
45 weeks 3 days ago
49 weeks 5 days ago
51 weeks 3 days ago
51 weeks 3 days ago
1 year 1 week ago
1 year 6 weeks ago
1 year 6 weeks ago