What is <cycle> in data?

Viewed 701

(I use OCaml version 4.02.3)

I defined a type self

# type self = Self of self;;
type self = Self of self 

and its instance s

# let rec s = Self s;;
val s : self = Self <cycle>

Since OCaml is a strict language, I expected defining s will fall into infinite recursion. But the interpreter said s has a value and it is Self <cycle>.

I also applied a function to s.

# let f (s: self) = 1;;
val f : self -> int = <fun> 
# f s;;
- : int = 1 

It seems s is not evaluated before the function application (like in non-strict language).

How OCaml deal with cyclic data like s? Self <cycle> is a normal form?

1 Answers
Related