4 karma · joined Aug 17, 2014 (12y ago) · 6 submissions
comment 3y ago · link · parent
I'm not familiar with the origin of traits/mixins in the OOP world, but my understanding is that they generally contain implementations of methods; they are a "part of" a class. Type classes and Rust traits, however, are more like interfaces. I'm pretty confident you won't find any notion of trait that predates type classes and can define what a Functor or Monad is. My reading of the SO answer you link is that Rust traits started off similar to type classes and have grown closer and closer over time. I'm not sure what a clearer indication of Haskell's influence would look like!
comment 3y ago · link · parent
My understanding is that "trait" is an unfortunately overloaded term. Traits in Rust are much more closely related to Haskell's type classes than to traits in the OOP sense.
comment 10y ago · link · parent
You're on the right track here. There's a very intuitive definition for 'compiler correctness':
Take any program in the source language and the corresponding target language program that a compiler gives you. Now run both programs using the semantics for the languages that each program is written in. If doing this gives you two equivalent results for all valid source programs, then your compiler is correct.
Assuming you have a good definition of 'equivalent results', this definition works very nicely for whole program compilers like the original work on CompCert. But what if you want to compile a component on its own, and then link it with a program later? It's not even obvious what correctness should mean if you support separate compilation because you can't 'run' a component.
It turns out there are different kinds of guarantees you might want to make about a compiler that constitute what is referred to as 'compositional compiler correctness'. Full abstraction is one of the strongest such guarantees. The abstract for this paper says that full abstraction means 'two source components are observationally equivalent in the source language if and only if their translations are observationally equivalent in the target'.
The key concept in this definition is the idea of 'observational equivalence'. We can say that two components C1 and C2 are observationally equivalent if for all programs P, there is no way for P to tell C1 and C2 apart; it must behave the same when linked with either one. That is, all of the observations that P can make about the component it's linked with are the same for both C1 and C2.
[1] (mentioned by the LtU post) talks a bit more about full abstraction and shows some issues that can arise when compilers accidentally break full abstraction. On the other hand, there are cases where it's impossible to write a fully abstract compiler. For example, if you have reflection in your target language but not your source language, it's likely that target level programs will always be able to distinguish between components which were equivalent in the source language. [2] is a good overview of many of the issues for those interested in compositional compiler correctness.
[1] http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.540... [2] http://www.ccs.neu.edu/home/amal/papers/verifcomp.pdf
comment 11y ago · link · parent