This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Re: variables in 'let rec'
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2000-03-29 (17:24) From: Sven LUTHER Subject: Re: variables in 'let rec'
```On Tue, Mar 28, 2000 at 11:03:36AM +1000, Max Skaller wrote:
> Damien Doligez wrote:
> >
> > >From: Max Skaller <maxs@in.ot.com.au>
> > >
> > >Alternatively, you can just use
> > >
> > >       let rec x' () = ...
> > >       and ...
> > >       let x = x()
> > >
> > >in lieu of what you really wanted: (that is,
> > >there is a workaround).
> >
> > But that doesn't work for "let rec x = 1 :: x", which is the most
> > interesting feature of O'Caml's recursive value definitions.
>
> 	It doesn't?
>
> 	let rec x'() = 1 :: x()'
> 	let x = x'()

FYI :

bash-2.03\$ ocaml
Objective Caml version 2.99 (99/12/08)

# let rec x = 1 :: x ;;
val x : int list =
[1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1;
1; 1; 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