(I使用OCaml的版本4.02.3)什麼是<cycle>的數據?
予定義的類型self
# type self = Self of self;;
type self = Self of self
和它的實例s
# let rec s = Self s;;
val s : self = Self <cycle>
由於OCaml is a strict language,我預期限定s
將陷入無限遞歸。但口譯員說s
有一個值,它是Self <cycle>
。
我還將一個函數應用於s
。
# let f (s: self) = 1;;
val f : self -> int = <fun>
# f s;;
- : int = 1
看來s
不計算功能的應用程序之前(如在非嚴格的語言)。
OCaml如何處理像s
這樣的循環數據? Self <cycle>
是一種正常的形式?