Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re: [Caml-devel] Feature request - recursive definition of object values (PR#3389) #3394

Closed
vicuna opened this issue Dec 22, 2004 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Dec 22, 2004

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

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

@vicuna
Copy link
Author

vicuna commented Jan 28, 2005

Comment author: administrator

see #3389

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant