You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I would like to use let rec for the recursive definition of
object values.
Something along the lines of:
class number_stream (first : int) (next : number_stream) = object
val v = first
val next = next
end
let rec ones = new number_stream 1 ones
in ones;;
Unfortunately, with the call-by-value semantics of the language, the
above definition is ill-founded. There is no concept of "uninitialized
object", like is used for datatypes in recursive value definitions.
There is a workaround:
class number_stream (first : int) (next : number_stream Lazy.t) =
object
method v = first
method next = Lazy.force next
end
let rec ones = lazy (new number_stream 1 ones)
let ones = Lazy.force ones
Jacques
The text was updated successfully, but these errors were encountered:
Original bug ID: 3394
Reporter: administrator
Status: closed
Resolution: won't fix
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)
Bug description
From: ethan.aubin@pobox.com
Unfortunately, with the call-by-value semantics of the language, the
above definition is ill-founded. There is no concept of "uninitialized
object", like is used for datatypes in recursive value definitions.
There is a workaround:
class number_stream (first : int) (next : number_stream Lazy.t) =
object
method v = first
method next = Lazy.force next
end
let rec ones = lazy (new number_stream 1 ones)
let ones = Lazy.force ones
Jacques
The text was updated successfully, but these errors were encountered: