在Leroy's paper如何遞歸模塊OCaml中被輸入,它被寫入的模塊是在由模塊類型的近似值的環境檢查: module rec A = ... and B = ... and C = ...
的環境{A - >約(A ); B - >約(B);首先建立C→C(近似)),然後用於計算A,B和C的類型。 我注意到,在某些情況下,近似值不夠好,並且類型檢查失敗。特別是,在將編譯單元源放入遞歸模塊
typedefs不是強類型的原因是什麼?有沒有我看不到的好處,還是因爲向後兼容?看到這個例子: typedef int Velocity;
void foo(Velocity v) {
//do anything;
}
int main() {
int i=4;
foo(i); //Should result in compile error if strong
有沒有一種將枚舉類傳遞給函數的簡潔方法? 考慮這樣的事情: public enum MyEnum implements XYZ {
//enum values
A,
B,
C;
}
public void getEnumeration(final Class<? extends XYZ> myEnum) {
//go through en
可能重複: Varying behavior for possible loss of precision 我發現Java的強類型檢查的不一致在編譯時。 請看下面的代碼: int sum = 0;
sum = 1; //is is OK
sum = 0.56786; //compile error because of precision loss, and strong typing
su