caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: variables in 'let rec'
@ 2000-03-25 14:55 Damien Doligez
  2000-03-28  1:03 ` Max Skaller
  0 siblings, 1 reply; 9+ messages in thread
From: Damien Doligez @ 2000-03-25 14:55 UTC (permalink / raw)
  To: caml-list

>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.

-- Damien



^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: variables in 'let rec'
@ 2000-03-28 10:01 Damien Doligez
  2000-03-30  9:19 ` John Max Skaller
  0 siblings, 1 reply; 9+ messages in thread
From: Damien Doligez @ 2000-03-28 10:01 UTC (permalink / raw)
  To: caml-list

>From: Max Skaller <maxs@in.ot.com.au>

>        let rec x'() = 1 :: x()'
>        let x = x'()
>
>Seems to work fine. Of course, this will loop forever in an eager
>language: the result is an infinite list of 1s.

Looping forever is not quite the same as returning an infinite list
of 1s, which is what the current implementation does for
    let rec x = 1::x

-- Damien



^ permalink raw reply	[flat|nested] 9+ messages in thread
* variables in 'let rec'
@ 2000-03-22  9:41 David Chemouil
  2000-03-23  1:37 ` Max Skaller
  2000-03-23 15:57 ` Xavier Leroy
  0 siblings, 2 replies; 9+ messages in thread
From: David Chemouil @ 2000-03-22  9:41 UTC (permalink / raw)
  To: caml-list


hi


I'm currently writing a program where I need to create both variables
and functions in a 'let rec'. The problem is that it is not allowed to
define a simple variable (i.e not a variant) in a 'let rec', because it
would be able to write things such as:

# let rec x = x+1;;
This kind of expression is not allowed as right-hand side of `let rec'

This error message seems okay to me.

However, the error message also occurs in situations where there is no
problem:

# let rec x = fact 5    (* using usual fact *)
              ^^^^^^
  and even = function
  | 0 -> true
  | n -> odd (n-1)
  and odd = function
  | 1 -> true
  | n -> even (n-1);;
This kind of expression is not allowed as right-hand side of `let rec'

What is "funny" is that it is possible to write 'Some (fact 5)'...

I wonder, then, if it would be possible to be a little less strict in
the typing policy. I believe however that it must be hard to perform
this, because it believe it is undecidable in the general case. But
isn't it possible to find a less strict policy which remains decidable?
For example, what if, in the typer, the 'let rec ... and ...' definition
was split in two parts: 
- the first part would be typed first: it would contain the variable
definitions which would be typed as a normal 'let ... and ...'.
- the second part would be typed as the current 'let rec ... and ...',
but the environment would contain the variables typed in the first part.

This system would enable to create variables in a 'let rec', but would
still forbid :
- to define mutually recursive variables
- to define non-recursive functions within a 'let rec'.


Of course, I guess the problem must be harder than that, but I think the
current system isn't completely "natural", as it forbids something that
is mathematically correct... 

Anyway, if this problem is really to complex, or undecidable, or not
worth the effot, why not allow any variable definition in a 'let rec'
and print a warning message? Then, the programmer would decide if the
definition may lead to an error...


regards

dc

-- 
David Chemouil [mailto:chemouil@enseeiht.fr] [mobile: 06 84 16 26 65]

Laboratoire d'informatique et de mathématiques appliquées (IRIT-INPT)



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2000-04-02 21:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-25 14:55 variables in 'let rec' Damien Doligez
2000-03-28  1:03 ` Max Skaller
2000-03-29 11:29   ` Sven LUTHER
2000-03-30  9:52     ` John Max Skaller
  -- strict thread matches above, loose matches on Subject: below --
2000-03-28 10:01 Damien Doligez
2000-03-30  9:19 ` John Max Skaller
2000-03-22  9:41 David Chemouil
2000-03-23  1:37 ` Max Skaller
2000-03-23 15:57 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).