Version française
Home     About     Download     Resources     Contact us    

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

Browse thread
[Caml-list] beginner question about tail recursion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-08-31 (10:32)
From: skaller <skaller@o...>
Subject: Re: [Caml-list] beginner question about tail recursion
On Sun, 2003-08-31 at 16:33, Matt Gushee wrote:

> 2. The recursive call can't be within a 'try' block.

I think that is not quite the correct rule, the rule should
be that the call can't cross a try block boundary.
For example:

let g x = 
	let y = 
		try h x with _ -> []
	in g y

This example _contains_ a try block.

let f x = 
		let g x = h x
		in g x
	with _ -> ...

this example is _contained in_ a try block.

Both have tail calls to g. But in this example:

1  let rec readlines chnl =
2    try
3      let line = input_line chnl in
4      line :: (readlines chnl)
5    with End_of_file -> []

the call of readlines _crosses_ a try
block boundary.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: